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

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

转自:http://blog.csdn.net/chenqiai0/article/details/8648246

在学习 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();

}

 
原文地址:https://www.cnblogs.com/ttzm/p/5531127.html