• 11384阅读
  • 6回复

vs2005+QT4商业版编译问题 [复制链接]

上一主题 下一主题
离线fengying
 
只看楼主 倒序阅读 楼主  发表于: 2009-02-25
— 本帖被 XChinux 从 Qt for Linux/X11 移动到本区(2010-02-08) —
我是一个新手,在用vs2005+QT4商业版第一次编程时碰到一下问题:
程序:
#include <Qt/qapplication.h>
#include <QtGui/QLabel.h>
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QLabel *label = new QLabel("Hello Qt!");
    label->show();
    return app.exec();
}
环境变量设置为:include:C:\Qt2005\4.4.3\include
                               lib:C:\Qt2005\4.4.3\lib

错误如下,怎么解决?
------ Build started: Project: dd, Configuration: Debug Win32 ------
Linking...
hh.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QApplication::~QApplication(void)" (__imp_??1QApplication@@UAE@XZ) referenced in function _main
hh.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static int __cdecl QApplication::exec(void)" (__imp_?exec@QApplication@@SAHXZ) referenced in function _main
hh.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __thiscall QWidget::show(void)" (__imp_?show@QWidget@@QAEXXZ) referenced in function _main
hh.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QString::~QString(void)" (__imp_??1QString@@QAE@XZ) referenced in function _main
hh.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QLabel::QLabel(class QString const &,class QWidget *,class QFlags<enum Qt::WindowType>)" (__imp_??0QLabel@@QAE@ABVQString@@PAVQWidget@@V?$QFlags@W4WindowType@Qt@@@@@Z) referenced in function _main
hh.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QString::QString(char const *)" (__imp_??0QString@@QAE@PBD@Z) referenced in function _main
hh.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall QApplication::QApplication(int &,char * *,int)" (__imp_??0QApplication@@QAE@AAHPAPADH@Z) referenced in function _main
hh.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __thiscall QLabel::metaObject(void)const " (?metaObject@QLabel@@UBEPBUQMetaObject@@XZ)
hh.obj : error LNK2001: unresolved external symbol "public: virtual void * __thiscall QLabel::qt_metacast(char const *)" (?qt_metacast@QLabel@@UAEPAXPBD@Z)
hh.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall QLabel::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@QLabel@@UAEHW4Call@QMetaObject@@HPAPAX@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall QLabel::event(class QEvent *)" (?event@QLabel@@MAE_NPAVQEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall QObject::eventFilter(class QObject *,class QEvent *)" (?eventFilter@QObject@@UAE_NPAV1@PAVQEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QObject::timerEvent(class QTimerEvent *)" (?timerEvent@QObject@@MAEXPAVQTimerEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QObject::childEvent(class QChildEvent *)" (?childEvent@QObject@@MAEXPAVQChildEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QObject::customEvent(class QEvent *)" (?customEvent@QObject@@MAEXPAVQEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QObject::connectNotify(char const *)" (?connectNotify@QObject@@MAEXPBD@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QObject::disconnectNotify(char const *)" (?disconnectNotify@QObject@@MAEXPBD@Z)
hh.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall QWidget::setVisible(bool)" (?setVisible@QWidget@@UAEX_N@Z)
hh.obj : error LNK2001: unresolved external symbol "public: virtual class QSize __thiscall QLabel::sizeHint(void)const " (?sizeHint@QLabel@@UBE?AVQSize@@XZ)
hh.obj : error LNK2001: unresolved external symbol "public: virtual class QSize __thiscall QLabel::minimumSizeHint(void)const " (?minimumSizeHint@QLabel@@UBE?AVQSize@@XZ)
hh.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall QLabel::heightForWidth(int)const " (?heightForWidth@QLabel@@UBEHH@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QLabel::mousePressEvent(class QMouseEvent *)" (?mousePressEvent@QLabel@@MAEXPAVQMouseEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QLabel::mouseReleaseEvent(class QMouseEvent *)" (?mouseReleaseEvent@QLabel@@MAEXPAVQMouseEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::mouseDoubleClickEvent(class QMouseEvent *)" (?mouseDoubleClickEvent@QWidget@@MAEXPAVQMouseEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QLabel::mouseMoveEvent(class QMouseEvent *)" (?mouseMoveEvent@QLabel@@MAEXPAVQMouseEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::wheelEvent(class QWheelEvent *)" (?wheelEvent@QWidget@@MAEXPAVQWheelEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QLabel::keyPressEvent(class QKeyEvent *)" (?keyPressEvent@QLabel@@MAEXPAVQKeyEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::keyReleaseEvent(class QKeyEvent *)" (?keyReleaseEvent@QWidget@@MAEXPAVQKeyEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QLabel::focusInEvent(class QFocusEvent *)" (?focusInEvent@QLabel@@MAEXPAVQFocusEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QLabel::focusOutEvent(class QFocusEvent *)" (?focusOutEvent@QLabel@@MAEXPAVQFocusEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::enterEvent(class QEvent *)" (?enterEvent@QWidget@@MAEXPAVQEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::leaveEvent(class QEvent *)" (?leaveEvent@QWidget@@MAEXPAVQEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QLabel::paintEvent(class QPaintEvent *)" (?paintEvent@QLabel@@MAEXPAVQPaintEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::moveEvent(class QMoveEvent *)" (?moveEvent@QWidget@@MAEXPAVQMoveEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::resizeEvent(class QResizeEvent *)" (?resizeEvent@QWidget@@MAEXPAVQResizeEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::closeEvent(class QCloseEvent *)" (?closeEvent@QWidget@@MAEXPAVQCloseEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QLabel::contextMenuEvent(class QContextMenuEvent *)" (?contextMenuEvent@QLabel@@MAEXPAVQContextMenuEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::tabletEvent(class QTabletEvent *)" (?tabletEvent@QWidget@@MAEXPAVQTabletEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::actionEvent(class QActionEvent *)" (?actionEvent@QWidget@@MAEXPAVQActionEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::dragEnterEvent(class QDragEnterEvent *)" (?dragEnterEvent@QWidget@@MAEXPAVQDragEnterEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::dragMoveEvent(class QDragMoveEvent *)" (?dragMoveEvent@QWidget@@MAEXPAVQDragMoveEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::dragLeaveEvent(class QDragLeaveEvent *)" (?dragLeaveEvent@QWidget@@MAEXPAVQDragLeaveEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::dropEvent(class QDropEvent *)" (?dropEvent@QWidget@@MAEXPAVQDropEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::showEvent(class QShowEvent *)" (?showEvent@QWidget@@MAEXPAVQShowEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::hideEvent(class QHideEvent *)" (?hideEvent@QWidget@@MAEXPAVQHideEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall QWidget::winEvent(struct tagMSG *,long *)" (?winEvent@QWidget@@MAE_NPAUtagMSG@@PAJ@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QLabel::changeEvent(class QEvent *)" (?changeEvent@QLabel@@MAEXPAVQEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::inputMethodEvent(class QInputMethodEvent *)" (?inputMethodEvent@QWidget@@MAEXPAVQInputMethodEvent@@@Z)
hh.obj : error LNK2001: unresolved external symbol "public: virtual class QVariant __thiscall QWidget::inputMethodQuery(enum Qt::InputMethodQuery)const " (?inputMethodQuery@QWidget@@UBE?AVQVariant@@W4InputMethodQuery@Qt@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual bool __thiscall QLabel::focusNextPrevChild(bool)" (?focusNextPrevChild@QLabel@@MAE_N_N@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::styleChange(class QStyle &)" (?styleChange@QWidget@@MAEXAAVQStyle@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::enabledChange(bool)" (?enabledChange@QWidget@@MAEX_N@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::paletteChange(class QPalette const &)" (?paletteChange@QWidget@@MAEXABVQPalette@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::fontChange(class QFont const &)" (?fontChange@QWidget@@MAEXABVQFont@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::windowActivationChange(bool)" (?windowActivationChange@QWidget@@MAEX_N@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual void __thiscall QWidget::languageChange(void)" (?languageChange@QWidget@@MAEXXZ)
hh.obj : error LNK2001: unresolved external symbol "public: virtual int __thiscall QWidget::devType(void)const " (?devType@QWidget@@UBEHXZ)
hh.obj : error LNK2001: unresolved external symbol "public: virtual class QPaintEngine * __thiscall QWidget::paintEngine(void)const " (?paintEngine@QWidget@@UBEPAVQPaintEngine@@XZ)
hh.obj : error LNK2001: unresolved external symbol "public: virtual struct HDC__ * __thiscall QWidget::getDC(void)const " (?getDC@QWidget@@UBEPAUHDC__@@XZ)
hh.obj : error LNK2001: unresolved external symbol "public: virtual void __thiscall QWidget::releaseDC(struct HDC__ *)const " (?releaseDC@QWidget@@UBEXPAUHDC__@@@Z)
hh.obj : error LNK2001: unresolved external symbol "protected: virtual int __thiscall QWidget::metric(enum QPaintDevice::PaintDeviceMetric)const " (?metric@QWidget@@MBEHW4PaintDeviceMetric@QPaintDevice@@@Z)
hh.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall QLabel::~QLabel(void)" (__imp_??1QLabel@@UAE@XZ) referenced in function "public: virtual void * __thiscall QLabel::`scalar deleting destructor'(unsigned int)" (??_GQLabel@@UAEPAXI@Z)
D:\My Documents\Visual Studio 2005\Projects\dd\Debug\dd.exe : fatal error LNK1120: 62 unresolved externals
Build log was saved at "file://d:\My Documents\Visual Studio 2005\Projects\dd\dd\Debug\BuildLog.htm"
dd - 63 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
离线浪漫天使
只看该作者 1楼 发表于: 2009-02-25
估计是没有经过pro直接用vs写个main函数就编。。就算这样也应该在工程属性设置一下要链接的库啊。。。
离线fengying
只看该作者 2楼 发表于: 2009-02-25
我实在vs里面建立了一个空白工程啊,然后直接建立一个.cpp文件。

请高手讲解具体操作过程!在线等待
离线fengying
只看该作者 3楼 发表于: 2009-02-26
怎么没有人回复呢
离线fengying
只看该作者 4楼 发表于: 2009-02-26
已经解决
离线kcir
只看该作者 5楼 发表于: 2009-03-05
請問可以敘述一下是如何解決的嗎?
我現在的狀況和你完全相同...
离线yxhappy
只看该作者 6楼 发表于: 2009-10-30
呵呵,是因为没有moc,信号和插槽机制,必须定义Q_OBJECT宏,标准c++没有对Qt的元对象系统所需要的动态元信息提供支持,qt提供了moc工具解决这个问题。
建议大家把解决的问题的方法分享一下。
GENERATE MOC FILES FOR HEADERS USING QT EVENTS (Q_OBJECT):
Perform this step for all header files that inherit from a QT class - i.e. any class with Q_OBJECT.  The following example uses a ficticious header file called MyHeaderFile.h You must fully qualify where the header file is or the moc utility will not find it.

In the Solution Explorer, right Click on MyHeaderFile.h and select Properties -> Custom Build Step -> General  
Set Command Line to $(QTDIR)\bin\moc MyHeaderFile.h -o tmp\moc\moc_MyHeaderFile.cpp
Set Description to Moc'ing MyHeaderFile.h ...
Set Outputs to tmp\moc\moc_MyHeaderFile.cpp
Set Additional Dependences $(QTDIR)\bin\moc.exe;
Replace MyHeaderFile with the actual name of the header file to be Moc'd.  

Screenshot8.gif
Screenshot9.gif  


7) ADD THE MOC FILES TO YOUR PROJECT:
First, build your project by selecting Build -> Build Solution or (F7) to generate moc files (you'll get a bunch of linking errors - don't worry).

From the Solution Explorer, right click on the  Project_Name and select Add -> New Folder
Name the new folder "Generated Moc Files" (or whatever you want).

Again, from the Solution Explorer right click on the "Generated Moc Files" folder and select Add -> Add Existing Item

Lastly, locate the moc file from the directory specified in step 6 (i.e. tmp\moc\moc_MyHeaderFile.cpp) to add it to your project.

That's it, you should be up and running.  Good Luck.
快速回复
限100 字节
 
上一个 下一个