Unresolved external symbol "public: virtual struct QMetaObject const * __thiscall Parent

后端 未结 23 2368
醉话见心
醉话见心 2020-11-30 21:33

I inherited a class from QObject :

class Parent: public QObject
{
    Q_OBJECT
    QObject* cl;

public:
    Parent(QObject *parent=0):QObject(parent) {
            


        
23条回答
  •  忘掉有多难
    2020-11-30 22:10

    My problem was that one of my files that used a Qt macro didn't get moc'ed. I found out, that the Qt Plugin for Visual Studio doesn't recognize the Q_NAMESPACE macro and therefore doesn't add the file to the moc'ing list.

    So I used the solution from this answer to add the file to the mic'ing list:

    You should find a .h file which has successfully generated "moc_*", and copy all the contents in "Custom Build Tool -> General" to the new .h file setting page.

    Be careful with the different options for Debug and Release-Mode.

    After that, build your project.

    Build it once each in Debug and Release-Mode

    Finally, add the generated "moc_*" file to your project.

    Now, "moc_filename.cpp" should be in Generated Files\Debug and Generated Files\Release.

    Right click on each of them and change thair properties:

    • The file in Debug: Change configuration to Release and then change General->Excluded from build to yes.
    • The file in Release: Change configuration to Debug and then change General->Excluded from build to yes.

提交回复
热议问题