I'm trying to use Qt's signals-and-slots mechanism with custom enumeration types.
I have read all the following, and none of it helped:
DetectorEngineThread.h:
class DetectorEngineThread : public QThread
{
Q_OBJECT
Q_ENUMS(ErrorCode)
Q_ENUMS(Status)
public:
enum ErrorCode
{
...
};
enum Status
{
...
};
...
signals:
void statusChanged(Status newStatus);
void processingError(ErrorCode code);
};
Q_DECLARE_METATYPE(DetectorEngineThread::ErrorCode)
Q_DECLARE_METATYPE(DetectorEngineThread::Status)
MainWindow.h:
...
#include "DetectorEngineThread.h"
...
class MainWindow : public QMainWindow
{
Q_OBJECT
...
private:
DetectorEngineThread* m_detEng;
...
private slots:
void on_detEng_statusChanged(DetectorEngineThread::Status newStatus);
void on_detEng_processingError(DetectorEngineThread::ErrorCode errorCode);
...
};
MainWindow.cpp:
...
#include "MainWindow.h"
...
MainWindow::MainWindow(...) : ...
{
...
qRegisterMetaType<DetectorEngineThread::Status>("DetectorEngineThread::Status");
qRegisterMetaType<DetectorEngineThread::ErrorCode>("DetectorEngineThread::ErrorCode");
...
m_detEng = new DetectorEngineThread(...);
connect(m_detEng, SIGNAL(statusChanged(DetectorEngineThread::Status)),
this, SLOT(on_detEng_statusChanged(DetectorEngineThread::Status)), Qt::QueuedConnection);
connect(m_detEng, SIGNAL(processingError(DetectorEngineThread::ErrorCode)),
this, SLOT(on_detEng_processingError(DetectorEngineThread::ErrorCode)), Qt::QueuedConnection);
...
}
...
void MainWindow::on_detEng_statusChanged(DetectorEngineThread::Status newStatus)
{
...
}
void MainWindow::on_detEng_processingError(DetectorEngineThread::ErrorCode errorCode)
{
...
}
...
During runtime, I get the following messages (in the Application Output panel in Qt Creator):
Object::connect: No such signal
DetectorEngineThread::statusChanged(DetectorEngineThread::Status) in ...
Object::connect: No such signal
DetectorEngineThread::processingError(DetectorEngineThread::ErrorCode) in ...
And obviously the slots' code never run, despite the fact that matching signals are emitted.
I tried:
Enums declared in signals and slots should be fully qualified so:
void statusChanged(Status newStatus);
void processingError(ErrorCode code);
Should be:
void statusChanged(DetectorEngineThread::Status newStatus);
void processingError(DetectorEngineThread::ErrorCode code);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With