Compile errors occurred. "qmake" swears:

main.o: in function `gdbInterface::gdbInterface(QProcess): undefined reference to `vtable for gdbInterface' main.o: in function `gdbInterface::~gdbInterface()': undefined reference to `vtable for gdbInterface' collect2: error: ld returned 1 exit status 

I understand that the constructor and the destructor are inherited incorrectly.

Code:

 #include <QCoreApplication> #include <QObject> #include <QIODevice> #include <QProcess> #include <QDebug> class gdbInterface : public QObject { Q_OBJECT public slots: void onGDBConnected(); public: gdbInterface(QProcess &gdb); }; void gdbInterface::onGDBConnected(){ } gdbInterface::gdbInterface(QProcess &gdb){ connect(&gdb, &QProcess::started, this , &gdbInterface::onGDBConnected); } int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); QProcess gdb; QString gdbProgram; QStringList gdbArguments; gdbArguments << "-q" << "/home/byeti/project/meerkat/meerkat_src/rat_lab" ;//<< "--interpreter=mi"; qint64* gdbPid = nullptr; gdbInterface interface(gdb); gdb.setProgram("gdb"); gdb.setArguments(gdbArguments); gdb.startDetached(gdbPid); gdb.close(); getchar(); return a.exec(); } 
  • You need to regenerate the MOC file and make sure that it participates in the compilation of your project. - AnT

1 answer 1

Add at the very end of the file, after the closing parenthesis:

 #include "main.moc" 
  • Written by its effects does not differ from the code in question. There, the default constructor for the underlying QObject is also invoked. - VTT
  • Is the ancestor's default constructor called by itself? I forgot this moment) - Alexander Chernin
  • Yes, the default base object constructor may be called implicitly. - VTT
  • Thanks, I'll fix it now - Alexander Chernin
  • Sergey, Alexander, thanks for the advice. Generated main.moc file, added it to the project, tried to compile, two similar errors appeared: / usr / bin / ld: main.o :(. Data.rel.ro._ZTV12gdbInterface [_ZTV12gdbInterface] + 0x30): undefined reference to ` gdbInterface :: gdbInterface () ' - ur_s