1. When VS2010 compiles QT, the following error occurs:
1>------started rebuild All: project: mydialog, config: Debug Win32------
1> build Start time is 2015/9/9 14:57:04.
1>initializebuildstatus:
1> is creating "Debug\mydialog.unsuccessfulbuild" because "AlwaysCreate" is already specified.
1>custombuild:
1> Moc ' ing LoginDlg.h ...
1>clcompile:
1> LoginDlg.cpp
1> main.cpp
1> is generating code ...
1>logindlg.obj:error LNK2001: unresolved external symbol "public:virtual struct qmetaobject const * __thiscall clogindlg::metaobject ( void) const "(?[email protected]@@[email protected]@XZ)
1>logindlg.obj:error LNK2001: unresolved external symbol "public:virtual void * __thiscall clogindlg::qt_metacast (char const *)" ([email protected]@@[email protected])
1>logindlg.obj:error LNK2001: unresolved external symbol "Public:virtual int __thiscall clogindlg::qt_metacall (enum Qmetaobject:: Call,int,void *) "([email protected]@@[email protected]@@[email protected])
1>d:\vc++\qtt\mydialog\\mydialog.exe:fatal error Lnk1120:3 an unresolved external command
1>
1> build failed.
1>
1> used Time 00:00:03.23
========== All rebuilds: 0 successful, 1 failed, 0 ========== skipped
2, the cause of the above error is due to missing a moc_xxx.cpp file in the Generatedfiles/debug file, as shown in:
3. What is the missing file name? So first to find the Q_object macro in that header file, such as in the macro in the LoginDlg.h file, then the generated file Moc_logindlg.cpp, to generate this file requires a Moc.exe file in the QT library, as shown in:
4. Enter into this directory via CMD and execute: MOC "d:\vc++\qtt\mydialog\mydialog\logindlg.h"-O "d:\vc++\qtt\mydialog\mydialog\moc_ LoginDlg.cpp "
As shown in the following:
5. A moc_logindlg.cpp file is then generated in the D:\vc++\qtt\mydialog\mydialog\ directory, as shown in:
6. Copy the Moc_logindlg.cpp file to the Generatedfiles/debug directory and add the file to VS, as shown in:
7, re-compile can
Vs2010+qt4 Compile error LNK2001: unresolved external symbol "public:virtual struct qmetaobject and other errors