錯誤:'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();

}

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM