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

后端 未结 23 2193
醉话见心
醉话见心 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:27

    I solved my problem by adding this to my header file :

    #ifndef MYCLASSNAME_H
    #define MYCLASSNAME_H
    
    ... // all the header file content.
    
    #endif
    
    0 讨论(0)
  • 2020-11-30 22:29

    I know that this is a very old question, but it seems to be still interesting (I've been here at least 4 or 5 times in the last months) and seems like I found another reason for which is possible to get this error.

    In my case in the header file I wrongly typed:

    #include "MyClass.h""
    

    Only after inspecting the whole output I found out that at that line the compiler was emitting a warning.

    Now that I removed the additional quotation mark my QObject compiles perfectly!

    0 讨论(0)
  • 2020-11-30 22:30

    If you're using Visual Studio, delete the line Q_OBJECT from the header file, save the file, put Q_OBJECT back into the header file, save the file again. This should generate the moc_* file and should build and link correctly.

    0 讨论(0)
  • 2020-11-30 22:30

    So the issue was I needed the Qt MOC compiler to compile my .h file. This is required for any classes that extend QObject or one of its children. The fix involed (for me) right-clicking on the header file, choosing Properties, and setting the Item Type to "Qt MOC Input", then hitting "Compile" on the header, and then adding the resulting moc_myfilename.cpp file to my project.

    0 讨论(0)
  • 2020-11-30 22:32

    For me, this is the cause: some header or source file not included in QT's project file

    0 讨论(0)
  • 2020-11-30 22:33

    I have the same problem, my solution was the encoding( my file with "UTF16LE BOM" can't generate with moc.exe ) , y create another file with ASCII enconding and it work.

    HxD HexEditor can help you to see the codification.

    0 讨论(0)
提交回复
热议问题