QT4
#include <qapplication>
#include <qlabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!");
//app.setMainWidget( label );//注釋掉就可以了
label->show();
return app.exec();
}
指令行,分3步:
1.qmake -project
2.qmake
3.make
執行成功後即可顯示
Qt3.x的HelloWorld
#include <QApplication>
#include <QPushbutton>
int main( int argc, char **argv )
{
QApplication a( argc, argv );
QPushButton hello( "Hello world!", 0 );
hello.resize( 100, 30 );
a.setMainWidget( &hello );
hello.show();
return a.exec();
}
同樣的3步
1.qmake -project
2.qmake
3.make
執行後顯示
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:12: error: ‘class QApplication’ has no member named ‘setMainWidget’
make: *** [hello.o] 錯誤 1
結果你編譯出錯,原因是因為QT4跟QT3有很多的變化,這可以參考QT4的手冊。
在QT4裡面沒有setMainWidget這個方法,解決方法是直接在.pro檔案中添加 QT += qt3support 就行了。
親自測試了兩種方法都是可行的!!