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

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

    Faced this issue in case of chained CMake targets. Turned out I had to enable CMAKE_AUTOMOC even in targets that didn't use Qt directly (transitively). Also turned out that CMAKE_AUTOMOC can't be used w/o find_package(QtX) in same CMakeLists.txt or CMakeLists.txt of parent.

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

    In my case, none of the above worked but it was totally my mistake.

    I had overrided virtual functions in .h file (declared them) but had never defined them in .cpp :)

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

    This happened to me recently when switching from MingW to MSVC. I had a prototyped class/struct listed as a class, and MingW didn't mind.

    MSVC definitely sees a difference between class and struct when prototyping is concerned.

    Hope that helps someone else one day.

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

    Either answer works for me in the VS 2013 environment. I eventually solve the problem by removing the .h/.cpp from project, and adding it back.

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

    I am working in VS2015 with an integrated Perforce p4v client. In my case Perforce tried to add moc file to a depo, when I reverted this operation, Perforce removed this moc file from project and deleted it. The file was recreated after the next compilation, but it wasn't included in project, I have to add it manually to Generated files, when I finally understood what was the problem.

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