首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网络技术 > 网络基础 >

异常:'class QApplication' has no member named 'setMainwidget'

2013-03-12 
错误:class QApplication has no member named setMainwidget在学习 QT的过程中 遇到了一个问题 错误如下:

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

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

}



热点排行