程序出错,求教
出错,求解:
程序的目的是为了实现软件界面的多语言切换.
使用了Qt Designer, Qt版本为3.1.1.
程序:
----dialog.h----
#ifndef DIALOG_H
#define DIALOG_H
#include <qdialog.h>
class QLabel;
class QPushButton;
class Dialog : public QDialog
{
Q_OBJECT
public :
Dialog( QWidget* parent = 0, const char* name = 0, bool model = False, WFlags f = 0 );
private :
// QLabel* label;
// QPushButton* okButton;
int flag;
private slots :
void retranslateStrings();
void switchLang();
}
#endif
----dialog.cpp-----
#include <qlayout.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qtranslator.h>
#include "dialog.h"
Dialog::Dialog( QWidget* parent, const char* name, bool model, WFlags f )
: QDialog( parent, name, model, f ) /* 1.0该行报错: ISO C++ forbids defining types within return type */
/* 1.1该行报错: no `Dialog QObject::Dialog(QWidget*, const char*, bool, unsigned int)' member function declared in class `QObject' */
/* 1.2该行报错: semicolon missing after declaration of `class Dialog' */
/* 1.3该行报错: type `class QDialog' is not a direct base of `QObject' */
{ /* 2.0该行报错: only constructors take base initializers */
QLabel* label = new QLabel( this, 0, 0 );/* 3.0该行报错: invalid conversion from `QObject* const' to `QWidget*'*/
/* 3.1该行报错: initializing argument 1 of `QLabel::QLabel(QWidget*, const char*, unsigned int)' */
QPushButton* okButton = new QPushButton( this, 0 );/* 4.0该行报错: invalid conversion from `QObject* const' to `QWidget*' */
/* 4.1该行报错: initializing argument 1 of `QPushButton::QPushButton(QWidget*,const char*)' */
connect( okButton, SIGNAL( clicked() ), this, SLOT( switchLang() ) );
flag = 0; /* 5.0该行报错: `flag' undeclared (first use this function) */
retranslateStrings(); /* 6.0该行报错:`retranslateStrings' undeclared (first use this function) */
QVBoxLayout* mainLayout = new QVBoxLayout;
mainLayout->addWidget( label );
mainLayout->addWidget( okButton );
// setLayout( mainLayout );
}
void Dialog::retranslateStrings()
{
label->setText( tr("Name") );
okButton->setText( tr("SwitchLanguage") );
this->setCaption( tr("Switch Language...") );
}
void Dialog::switchLang()
{
QTranslator translator( &app, 0 );
if( 0 == flag )
{
translator.load( "switchlang_zh" );
flag = 1;
}
else
{
flag = 0;
}
app.installTranslator( &translator );/* 7.0该行报错: `app' undeclared (first use this function) */
retranslateStrings();
}
------main.cpp------
#include <qapplication.h>
#include "dialog.h"
int main( int argc, char **argv )
{
QApplication app( argc, argv );
Dialog dialog( 0, 0, False, 0 );
dialog.show;
return app.exec();
}
改程序是在网上找的,调试后错误均出现在dialog.cpp中,我没有能够解决,请教:错误在哪里?