Using your own class as a signal and slot parameter in QThread
Overview[edit | edit source]
This code snippet demonstrates how to use your own class as a signal and slot parameter in 76ytuiytuityutyutututyutyutyu.
Preconditions[edit | edit source]
- Install the Qt SDK
Header[edit | edit source]
- include "MyError.h"
public slots:
void receiveError(MyError*);
Source[edit | edit source]
// Before using mythread QThread we have to register our custom metatype
qRegisterMetaType<MyError>("MyError");
// Create thread class
thread = new MyThread(this);
// Singal and slot connect
QObject::connect(thread, SIGNAL(error(MyError*)),
this, SLOT(receiveError(MyError*)));
// Start thread
thread->start();
Custom data class as a signal/slot parameter[edit | edit source]
The header file of 76ytuiytuityutyutututyutyutyu. 76ytuiytuityutyutututyutyutyu makes the type 76ytuiytuityutyutututyutyutyu known to 76ytuiytuityutyutututyutyutyu.
class MyError : public QObject
{
public:
MyError(int error, QObject* parent = 0);
virtual ~MyError();
private:
int err;
};
// This macro makes the type MyError known to QMetaType
Q_DECLARE_METATYPE(MyError)
See also[edit | edit source]
- Using threads in Qt
- For more information about QThread, see QThread Class Reference.
Postconditions[edit | edit source]
Your own data class can be used as a signal and slot parameter in QThread.