LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1124|回复: 2

编译问题,QT的

[复制链接]
发表于 2007-7-16 13:55:38 | 显示全部楼层 |阅读模式
一个简单的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
发表于 2007-7-16 15:09:12 | 显示全部楼层
在4.0下的确没有了setMainWidget。你把这行去掉就可以了。官方网站上就有很多例子你可以学习的

http://doc.trolltech.com/4.0/index.html
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-7-16 19:59:42 | 显示全部楼层
那如果现在我有多个widget在同一个window下,那时候还需要设置某个为main widget吗?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表