第一次学QT,简单的hello程序出错
源程序如下:
#include <qapplication.h>
#include <qpushbutton.h>
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();
}
执行:qmake -project
qmake
make
编译出错,如下:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/local/Trolltech/Qt-4.4.3/mkspecs/linux-g++ -I. -I/usr/local/Trolltech/Qt-4.4.3/include/QtCore -I/usr/local/Trolltech/Qt-4.4.3/include/QtCore -I/usr/local/Trolltech/Qt-4.4.3/include/QtGui -I/usr/local/Trolltech/Qt-4.4.3/include/QtGui -I/usr/local/Trolltech/Qt-4.4.3/include -I. -I. -I. -o hello.o hello.cpp
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:11: 错误:‘class QApplication’没有名为‘setMainWidget’的成员
make: *** [hello.o] 错误 1
我看了很多网上的很多帖子,有很多说法,可是因为初学,面对那些说法依然手足无措,尤其是混乱的QT产品版本啊,纠结难缠,编程序竟然被编程环境给撂倒了,那个郁闷……希望高手可以指点一二,给我一个具体的解决办法,我安装的是qt-x11-opensource-src-4.4.3在网上找了很久没有找到4.5.0版本的(没找对地方),arm-linux-gcc-4.4.3 。谢谢了。