Unsolved undefined reference to `vtable for myclass'
-
this is my header file for my class
#ifndef MASTERPAGEHANDLER_H #define MASTERPAGEHANDLER_H #include <QThread> #include <QObject> class MasterPageHandler : public QObject { Q_OBJECT public : Q_INVOKABLE bool status() const; public: bool m_status; public: //explicit MasterPageHandler(QObject *parent = nullptr); MasterPageHandler(); signals: void wirelessStateChange_signal(); public slots: void timer_tick_slot(); void scanProcessFinished(QString res); }; #endif // MASTERPAGEHANDLER_H
and this is my cpp file and i define another class in it for thread
#include "masterpagehandler.h" #include <QDebug> #include "Utility/networkmanagment.h" class myScanner :public QThread { Q_OBJECT public : myScanner(){} void run(){ NetworkManagment *nm=new NetworkManagment(); QString s=nm->CheckWifiOnline(); emit finishProcess(s); } signals : void finishProcess(QString res); }; MasterPageHandler::MasterPageHandler() : m_status(false) { } bool MasterPageHandler::status() const { return m_status; } void MasterPageHandler::scanProcessFinished(QString res){ } void MasterPageHandler::timer_tick_slot(){ myScanner *ms = new myScanner(); connect(ms , &myScanner::objectNameChanged, this , &MasterPageHandler::scanProcessFinished); ms->start(); }
i get this error undefined reference to `vtable for myScanner'
why? -
My suspicion is because your constructor is inlined, so g++ (which I'm pretty sure you use) doesn't know where to emit the
vtable
. Anyway, move the class into the header and use a non-inline constructor, rebuild and it should be fixed. -
Your class myScanner needs to be mocked (preprocessed by Qt).
Typically it is done by placing QObject subclass in a separate header file.
If you want to put it in cpp, you have to manually include the moc file.
Other actions may be required depending on your build tool. -
@kshegunov tnx solved
-
For further reference, g++ will emit the
vtable
just before the first non-inline function (MSVC doesn't have that problem for reasons beyond the scope of this discussion). Meaning it's a good idea to have your constructor in source to avoid this rather cryptic error.PS.
If the solution is satisfactory, please mark the thread as solved. We like seeing green instead of orange in the list. Thank you. -
This post is deleted!