您的位置:首页 > 移动开发

错误:'class QApplication' has no member named 'setMainwidget'

2016-05-26 14:56 393 查看

错误:'class QApplication' has no member named 'setMainwidget' 

转自:https://www.geek-share.com/detail/2573661020.html

在学习 QT的过程中 遇到了一个问题

错误如下:
'class QApplication' has no member named 'setMainWidget'

在 类QApplication里面 没有找到 setMainWidget 成员...

原因是:
Qt 3.x支持setMainWidget,但是Qt4已经取消了对setMainWidget的支持。

 

 

以下是一个QT3程序

#include<qapplication.h>

#include<qpushbutton.h>

int main( int argc, char*argv[])

{

QApplicationa( argc, argv );

QPushButtonhello( "Hello world!", 0 );

hello.resize( 100, 30 );

a.setMainWidget( &hello );

hello.show();

returna.exec();

}

*********************************

a.setMainWidget(&hello );

这个按钮被选为这个应用程序的主窗口部件。如果用户关闭了主窗口部件,应用程序就退出了。你不用必须设置一个主窗口部件,但绝大多数程序都有一个。

 

 

 

修改之后的QT4程序

 

#include<QApplication>

#include<QPushButton>

int main( int argc, char* argv[])

{

QApplication app(argc, argv );

QPushButton*hello = new QPushButton( "Hello world!", 0 );

hello-> resize( 100, 30 );

hello-> show();

return app.exec();

}

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: