Unresolved Externals In Parent After Deleting Child Class



  • I've created this simple class called DragButton which simply intercepts the mouse move event and updates the position of the button. It then gives out a new signal called mousemove that returns a pointer to the button itself for more control. I might change this later.

    #pragma once
    
    #include <QPushButton>
    
    class DragButton : public QPushButton
    {
        Q_OBJECT
    public:
        DragButton(QWidget *parent);
        void emitMouseMove() { mouseMove(this); }
        ~DragButton();
    
    signals:
        void mouseMove(QPushButton* button);
        
    protected:
        void mouseMoveEvent(QMouseEvent* event) override;
    };
    

    This solution works for a time. But after I created another button called NodeButton that would inherit this button with some more information to go along with the DragButton I ran into some errors and deleted the NodeButton class. And now the DragButton throws a bunch of unresolved externals:

    1>DragButton.obj : error LNK2001: unresolved external symbol "public: virtual struct QMetaObject const * __cdecl DragButton::metaObject(void)const " (?metaObject@DragButton@@UEBAPEBUQMetaObject@@XZ)
    1>DragButton.obj : error LNK2001: unresolved external symbol "public: virtual void * __cdecl DragButton::qt_metacast(char const *)" (?qt_metacast@DragButton@@UEAAPEAXPEBD@Z)
    1>DragButton.obj : error LNK2001: unresolved external symbol "public: virtual int __cdecl DragButton::qt_metacall(enum QMetaObject::Call,int,void * *)" (?qt_metacall@DragButton@@UEAAHW4Call@QMetaObject@@HPEAPEAX@Z)
    1>DragButton.obj : error LNK2019: unresolved external symbol "public: void __cdecl DragButton::mouseMove(class QPushButton *)" (?mouseMove@DragButton@@QEAAXPEAVQPushButton@@@Z) referenced in function "public: void __cdecl DragButton::emitMouseMove(void)" (?emitMouseMove@DragButton@@QEAAXXZ)
    

    I also got these unresolved externals earlier somehow and the only way for me to fix it was to remake the class? Is there anyway to fix this without remaking the class? Is there some extra step I need to take when deleting QT classes in vs. I've tried rebuilding, cleaning, manually deleting all the generated files. Nothing fixes it except remaking the class.
    Note: I'm using the Qt extension in visual studios.


  • Qt Champions 2016

    Is this in a library? If so you must export your classes (see here).
    If this is not a library, then there's something wrong with the moc - the generated file isn't linked for some reason. Try rerunning qmake and making a full rebuild.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.