|
一个简单的hello程序,但是编译有问题,源码和编译错误如下:
#include <QApplication>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLabel *label = new QLabel("Hello Qt!", 0);
app.setMainWidget(label);
label->show();
return app.exec();
}
编译错误提示:
g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -I. -I. -o hello.o hello.cpp
hello.cpp: In function ‘int main(int, char**)’:
hello.cpp:8: error: ‘class QApplication’ has no member named ‘setMainWidget’
make: *** [hello.o] Error 1
提示QApplication类没有setMainWidget这个成员函数,这是怎么回事?
不过,我用的是Qt4,程序是<<c++ GUI Qt3 编程>>这本书里面的例子,应该是Qt3的程序,是不是兼容的问题?下面是我机器上安装的Qt的信息,安装了Qt3的兼容阿,我的是ubuntu7.04版本:
defyer@ubuntuyn:~$ dpkg -l |grep qt4
rc libqt4-core 4.2.3-0ubuntu3 Qt 4 core non-GUI functionality runtime libr
ii libqt4-core-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 core non-GUI functionality runtime libr
ii libqt4-dev-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 development files
rc libqt4-gui 4.2.3-0ubuntu3 Qt 4 core GUI functionality runtime library
ii libqt4-gui-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 core GUI functionality runtime library
rc libqt4-qt3support 4.2.3-0ubuntu3 Qt 3 compatibility library for Qt 4
ii libqt4-qt3support-kdecopy 4.3.0~beta1-0ubuntu2 Qt 3 compatibility library for Qt 4
rc libqt4-sql 4.2.3-0ubuntu3 Qt 4 SQL database module
ii libqt4-sql-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 SQL database module
rc qt4-designer 4.2.3-0ubuntu3 Qt 4 Designer
ii qt4-designer-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 Designer
ii qt4-dev-tools-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 development tools
ii qt4-doc-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 API documentation
ii qt4-qtconfig-kdecopy 4.3.0~beta1-0ubuntu2 Qt 4 configuration tool |
|