Vs2010+qt4 Compile error LNK2001: unresolved external symbol "public:virtual struct qmetaobject and other errors

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.