程序出错,求教

fengwanzk 2011-05-25 06:37:44
出错,求解:
程序的目的是为了实现软件界面的多语言切换.
使用了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中,我没有能够解决,请教:错误在哪里?
...全文
354 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
fengwanzk 2011-05-26
  • 打赏
  • 举报
回复
确实如此,太大意了。谢谢。
dbzhang800 2011-05-25
  • 打赏
  • 举报
回复
类定义的大括号后面加分号 “;”

16,212

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧