Release/moc_Controller.cpp:-1: error: undefined reference to `Controller::handleResults(QString const&)'
Solved
General and Desktop
-
using code from https://doc.qt.io/qt-5/qthread.html, changed a few names, and split into .h and .cpp files, I get a moc file error.
.h file:
#ifndef CThreadCONTROLLER_H #define CThreadCONTROLLER_H #include <QObject> #include <QThread> class CThreadController : public QObject { Q_OBJECT QThread guiThread; public: // constructor CThreadController(); // destructor ~CThreadController(); public slots: void handleResults(const QString &); signals: void operate(const QString &); }; #endif // CThreadCONTROLLER_H
.cpp file:
#include "CThreadController.h" #include "CGUI.h" CThreadController::CThreadController() : QObject() { CNC::CGUI *gui = new CNC::CGUI; gui->moveToThread(&guiThread); connect(&guiThread, &QThread::finished, gui, &QObject::deleteLater); //connect(this, &CThreadController::operate, gui, &CNC::CGUI::doWork); //connect(gui, &CNC::CGUI::resultReady, this, &CThreadController::handleResults); guiThread.start(); } CThreadController::~CThreadController() { guiThread.quit(); guiThread.wait(); } /* Worker *worker = new Worker; worker->moveToThread(&workerThread); connect(&workerThread, &QThread::finished, worker, &QObject::deleteLater); connect(this, &Controller::operate, worker, &Worker::doWork); connect(worker, &Worker::resultReady, this, &Controller::handleResults); workerThread.start(); workerThread = guiThread *worker = *gui Worker = CNC::CGUI &Controller = &CThreadController */
errors:
:-1: error: moc_CThreadController.o: in function `CThreadController::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)':/home/michaeleric/build-GUI-Desktop-Release/moc_CThreadController.cpp:-1: error: undefined reference to `CThreadController::handleResults(QString const&)'
:-1: error: collect2: error: ld returned 1 exit status
i dont understand error. handleResults(QString const&) is unused on website code, nor in my code. only class name changed.
what is the error, and how to fix it. -
void CThreadController::handleResults(const QString &){}
was not in .cpp file