LinuxSir.cn,穿越时空的Linuxsir!

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

简单的 qt问题

[复制链接]
发表于 2004-12-5 23:21:45 | 显示全部楼层 |阅读模式
我 是照着 教程做的阿  why?
qt 的 代码文件名是qt.cpp
#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();
   
}


不 管是 用g++  -o qt qt.cpp

还 是 用 1 qmake -project
2 qmke
3make

都 出错
错误 的息信如下
longhrs@linux:~/qt> qmake -project
longhrs@linux:~/qt> qmake
longhrs@linux:~/qt> make
g++  -o qt qt.o    -L/usr/lib/ -L/usr/X11R6/lib/ -lXext -lX11 -lm
qt.o(.text+0x33): In function `main':
: undefined reference to `QApplication:Application[in-charge](int&, char**)'
qt.o(.text+0x44): In function `main':
: undefined reference to `QString:String[in-charge](char const*)'
qt.o(.text+0x62): In function `main':
: undefined reference to `QPushButton:PushButton[in-charge](QString const&, QWidget*, char const*)'
qt.o(.text+0x77): In function `main':
: undefined reference to `QString::shared_null'
qt.o(.text+0x81): In function `main':
: undefined reference to `QStringData::deleteSelf()'
qt.o(.text+0xa6): In function `main':
: undefined reference to `QPushButton::resize(int, int)'
qt.o(.text+0xb2): In function `main':
: undefined reference to `QApplication::setMainWidget(QWidget*)'
qt.o(.text+0xba): In function `main':
: undefined reference to `QWidget::show()'
qt.o(.text+0xc2): In function `main':
: undefined reference to `QApplication::exec()'
qt.o(.text+0xcc): In function `main':
: undefined reference to `QPushButton::~QPushButton [in-charge]()'
qt.o(.text+0xd4): In function `main':
: undefined reference to `QApplication::~QApplication [in-charge]()'
qt.o(.text+0xed): In function `main':
: undefined reference to `QApplication::~QApplication [in-charge]()'
qt.o(.text+0x113): In function `main':
: undefined reference to `QString::shared_null'
qt.o(.text+0x11d): In function `main':
: undefined reference to `QStringData::deleteSelf()'
qt.o(.text+0x129): In function `main':
: undefined reference to `QPushButton::~QPushButton [in-charge]()'
qt.o(.gnu.linkonce.r._ZTV6QGList+0xc): undefined reference to `QGList::clear()'
qt.o(.gnu.linkonce.r._ZTV6QGList+0x10): undefined reference to `QGList::~QGList [in-charge]()'
qt.o(.gnu.linkonce.r._ZTV6QGList+0x14): undefined reference to `QGList::~QGList [in-charge deleting]()'
qt.o(.gnu.linkonce.r._ZTV6QGList+0x18): undefined reference to `QPtrCollection::newItem(void*)'
qt.o(.gnu.linkonce.r._ZTV6QGList+0x20): undefined reference to `QGList::compareItems(void*, void*)'
qt.o(.gnu.linkonce.r._ZTV6QGList+0x24): undefined reference to `QGList::read(QDataStream&, void*&)'
qt.o(.gnu.linkonce.r._ZTV6QGList+0x28): undefined reference to `QGList::write(QDataStream&, void*) const'
qt.o(.gnu.linkonce.r._ZTI6QGList+0x8): undefined reference to `typeinfo for QPtrCollection'
qt.o(.gnu.linkonce.r._ZTV15QDragEnterEvent+0x10): undefined reference to `QDropEvent::format(int) const'
qt.o(.gnu.linkonce.r._ZTV15QDragEnterEvent+0x14): undefined reference to `QDropEvent::encodedData(char const*) const'
qt.o(.gnu.linkonce.r._ZTV15QDragEnterEvent+0x18): undefined reference to `QDropEvent::provides(char const*)const'
qt.o(.gnu.linkonce.r._ZTV15QDragEnterEvent+0x2c): undefined reference to `non-virtual thunk [nv:-12] to QDropEvent::format(int) const'
qt.o(.gnu.linkonce.r._ZTV15QDragEnterEvent+0x30): undefined reference to `non-virtual thunk [nv:-12] to QDropEvent::provides(char const*) const'
qt.o(.gnu.linkonce.r._ZTV15QDragEnterEvent+0x34): undefined reference to `non-virtual thunk [nv:-12] to QDropEvent::encodedData(char const*) const'
qt.o(.gnu.linkonce.r._ZTI14QDragMoveEvent+0x8): undefined reference to `typeinfo for QDropEvent'
qt.o(.gnu.linkonce.r._ZTV14QDragMoveEvent+0x10): undefined reference to `QDropEvent::format(int) const'
qt.o(.gnu.linkonce.r._ZTV14QDragMoveEvent+0x14): undefined reference to `QDropEvent::encodedData(char const*) const'
qt.o(.gnu.linkonce.r._ZTV14QDragMoveEvent+0x18): undefined reference to `QDropEvent::provides(char const*) const'
qt.o(.gnu.linkonce.r._ZTV14QDragMoveEvent+0x2c): undefined reference to `non-virtual thunk [nv:-12] to QDropEvent::format(int) const'
qt.o(.gnu.linkonce.r._ZTV14QDragMoveEvent+0x30): undefined reference to `non-virtual thunk [nv:-12] to QDropEvent::provides(char const*) const'
qt.o(.gnu.linkonce.r._ZTV14QDragMoveEvent+0x34): undefined reference to `non-virtual thunk [nv:-12] to QDropEvent::encodedData(char const*) const'
qt.o(.gnu.linkonce.t._ZN15QDragEnterEventD0Ev+0x14): In function `QDragEnterEvent::~QDragEnterEvent [in-charge deleting]()':
: undefined reference to `vtable for QDropEvent'
qt.o(.gnu.linkonce.t._ZN15QDragEnterEventD0Ev+0x1b): In function `QDragEnterEvent::~QDragEnterEvent [in-charge deleting]()':
: undefined reference to `vtable for QDropEvent'
qt.o(.gnu.linkonce.t._ZN15QDragEnterEventD0Ev+0x23): In function `QDragEnterEvent::~QDragEnterEvent [in-charge deleting]()':
: undefined reference to `QMimeSource::~QMimeSource [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN15QDragEnterEventD0Ev+0x2b): In function `QDragEnterEvent::~QDragEnterEvent [in-charge deleting]()':
: undefined reference to `QEvent::~QEvent [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN15QDragEnterEventD0Ev+0x46): In function `QDragEnterEvent::~QDragEnterEvent [in-charge deleting]()':
: undefined reference to `QEvent::~QEvent [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN15QDragEnterEventD1Ev+0x14): In function `QDragEnterEvent::~QDragEnterEvent [in-charge]()':
: undefined reference to `vtable for QDropEvent'
qt.o(.gnu.linkonce.t._ZN15QDragEnterEventD1Ev+0x1b): In function `QDragEnterEvent::~QDragEnterEvent [in-charge]()':
: undefined reference to `vtable for QDropEvent'
qt.o(.gnu.linkonce.t._ZN15QDragEnterEventD1Ev+0x23): In function `QDragEnterEvent::~QDragEnterEvent [in-charge]()':
: undefined reference to `QMimeSource::~QMimeSource [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN15QDragEnterEventD1Ev+0x2b): In function `QDragEnterEvent::~QDragEnterEvent [in-charge]()':
: undefined reference to `QEvent::~QEvent [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN15QDragEnterEventD1Ev+0x46): In function `QDragEnterEvent::~QDragEnterEvent [in-charge]()':
: undefined reference to `QEvent::~QEvent [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN14QDragMoveEventD1Ev+0x14): In function `QDragMoveEvent::~QDragMoveEvent [in-charge]()':
: undefined reference to `vtable for QDropEvent'
qt.o(.gnu.linkonce.t._ZN14QDragMoveEventD1Ev+0x1b): In function `QDragMoveEvent::~QDragMoveEvent [in-charge]()':
: undefined reference to `vtable for QDropEvent'
qt.o(.gnu.linkonce.t._ZN14QDragMoveEventD1Ev+0x23): In function `QDragMoveEvent::~QDragMoveEvent [in-charge]()':
: undefined reference to `QMimeSource::~QMimeSource [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN14QDragMoveEventD1Ev+0x2b): In function `QDragMoveEvent::~QDragMoveEvent [in-charge]()':
: undefined reference to `QEvent::~QEvent [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN14QDragMoveEventD1Ev+0x46): In function `QDragMoveEvent::~QDragMoveEvent [in-charge]()':
: undefined reference to `QEvent::~QEvent [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN14QDragMoveEventD0Ev+0x14): In function `QDragMoveEvent::~QDragMoveEvent [in-chargedeleting]()':
: undefined reference to `vtable for QDropEvent'
qt.o(.gnu.linkonce.t._ZN14QDragMoveEventD0Ev+0x1b): In function `QDragMoveEvent::~QDragMoveEvent [in-chargedeleting]()':
: undefined reference to `vtable for QDropEvent'
qt.o(.gnu.linkonce.t._ZN14QDragMoveEventD0Ev+0x23): In function `QDragMoveEvent::~QDragMoveEvent [in-chargedeleting]()':
: undefined reference to `QMimeSource::~QMimeSource [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN14QDragMoveEventD0Ev+0x2b): In function `QDragMoveEvent::~QDragMoveEvent [in-chargedeleting]()':
: undefined reference to `QEvent::~QEvent [not-in-charge]()'
qt.o(.gnu.linkonce.t._ZN14QDragMoveEventD0Ev+0x46): In function `QDragMoveEvent::~QDragMoveEvent [in-chargedeleting]()':
: undefined reference to `QEvent::~QEvent [not-in-charge]()'
collect2: ld returned 1 exit status
make: *** [qt] 错误 1
longhrs@linux:~/qt>   
   
用g++的出错 是

longhrs@linux:~/qt> g++ -I/usr/lib/qt3/include -o qt qt.cpp
qt.cpp:17:2: warning: no newline at end of file
/tmp/ccQf3y5F.o(.text+0x2f): In function `main':
: undefined reference to `QApplication:Application[in-charge](int&, char**)'
/tmp/ccQf3y5F.o(.text+0x47): In function `main':
: undefined reference to `QString:String[in-charge](char const*)'
/tmp/ccQf3y5F.o(.text+0x5d): In function `main':
: undefined reference to `QPushButton:PushButton[in-charge](QString const&, QWidget*, char const*)'
/tmp/ccQf3y5F.o(.text+0xb0): In function `main':
: undefined reference to `QPushButton::resize(int, int)'
/tmp/ccQf3y5F.o(.text+0xc6): In function `main':
: undefined reference to `QApplication::setMainWidget(QWidget*)'
/tmp/ccQf3y5F.o(.text+0xd8): In function `main':
: undefined reference to `QWidget::show()'
/tmp/ccQf3y5F.o(.text+0xe7): In function `main':
: undefined reference to `QApplication::exec()'
/tmp/ccQf3y5F.o(.text+0xff): In function `main':
: undefined reference to `QPushButton::~QPushButton [in-charge]()'
/tmp/ccQf3y5F.o(.text+0x10e): In function `main':
: undefined reference to `QApplication::~QApplication [in-charge]()'
/tmp/ccQf3y5F.o(.text+0x13a): In function `main':
: undefined reference to `QPushButton::~QPushButton [in-charge]()'
/tmp/ccQf3y5F.o(.text+0x15d): In function `main':
: undefined reference to `QApplication::~QApplication [in-charge]()'
/tmp/ccQf3y5F.o(.gnu.linkonce.r._ZTV6QGList+0xc): undefined reference to `QGList::clear()'
/tmp/ccQf3y5F.o(.gnu.linkonce.r._ZTV6QGList+0x10): undefined reference to `QGList::~QGList [in-charge]()'
/tmp/ccQf3y5F.o(.gnu.linkonce.r._ZTV6QGList+0x14): undefined reference to `QGList::~QGList [in-charge deleting]()'
/tmp/ccQf3y5F.o(.gnu.linkonce.r._ZTV6QGList+0x18): undefined reference to `QPtrCollection::newItem(void*)'
/tmp/ccQf3y5F.o(.gnu.linkonce.r._ZTV6QGList+0x20): undefined reference to `QGList::compareItems(void*, void*)'
/tmp/ccQf3y5F.o(.gnu.linkonce.r._ZTV6QGList+0x24): undefined reference to `QGList::read(QDataStream&, void*&)'
/tmp/ccQf3y5F.o(.gnu.linkonce.r._ZTV6QGList+0x28): undefined reference to `QGList::write(QDataStream&, void*) const'
/tmp/ccQf3y5F.o(.gnu.linkonce.t._ZN7QStringD1Ev+0x21): In function `QString::~QString [in-charge]()':
: undefined reference to `QString::shared_null'
/tmp/ccQf3y5F.o(.gnu.linkonce.t._ZN7QStringD1Ev+0x30): In function `QString::~QString [in-charge]()':
: undefined reference to `QStringData::deleteSelf()'
/tmp/ccQf3y5F.o(.gnu.linkonce.r._ZTI6QGList+0x8): undefined reference to `typeinfo for QPtrCollection'
collect2: ld returned 1 exit status
longhrs@linux:~/qt>
 楼主| 发表于 2004-12-5 23:23:50 | 显示全部楼层
不知道为什么 我的贴上有加了些怪表情阿
发表于 2004-12-6 07:07:35 | 显示全部楼层
-I$QTDIR/include -lqt
你需要在编译的时候指定include, 链接的时候指定lib.
 楼主| 发表于 2004-12-6 08:59:21 | 显示全部楼层

re

还得麻烦老兄 看一下 下、现在成这样了
longhrs@linux:~/qt> g++ -I/usr/lib/qt3/include  -lqt -o qt qt.cpp
qt.cpp:17:2: warning: no newline at end of file
/usr/lib/gcc-lib/i586-suse-linux/3.3.4/../../../../i586-suse-linux/bin/ld: cannot find -lqt
collect2: ld returned 1 exit status
longhrs@linux:~/qt>
 楼主| 发表于 2004-12-6 09:17:26 | 显示全部楼层

ok

longhrs@linux:~/qt> g++ -I/usr/lib/qt3/include  -L /usr/lib/qt3/lib/ -l qt  -o qt qt.cpp
qt.cpp:17:2: warning: no newline at end of file
longhrs@linux:~/qt> ls
Makefile  qt  qt.cpp  qt.cpp~  qt.o  qt.pro
longhrs@linux:~/qt> ./qt
就看见了个对话框 了
谢谢了
 楼主| 发表于 2004-12-6 09:18:17 | 显示全部楼层
不知道这个
qt.cpp:17:2: warning: no newline at end of file
是为什么?
发表于 2004-12-6 09:22:47 | 显示全部楼层
文件的最后没有换行符!
KDE/QT的书中说了,编译的时候需要加上头文件,而且他自己生成的makefile也需要稍微的改动一下!
 楼主| 发表于 2004-12-6 09:33:15 | 显示全部楼层
那怎么写 呢
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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