| ID | CS001428 | Creation date | June 16, 2009 |
| Platform | S60 3rd Edition, FP1, FP2 S60 5th Edition | Tested on devices | Nokia 5800 XpressMusic |
| Category | Qt for Symbian | Subcategory | Base/System |
| Keywords (APIs, classes, methods, functions): QThread, qRegisterMetaType, Q_DECLARE_METATYPE |
This code snippet demonstrates how to use your own class as a signal and slot parameter in QThread.
Note: In order to use this code, you need to have Qt for S60 installed on your platform.
#include "MyError.h"
public slots:
void receiveError(MyError*);
// 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();
The header file of MyError. Q_DECLARE_METATYPE(MyError) makes the type MyError known to QMetaType.
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)
Your own data class can be used as a signal and slot parameter in QThread.
No related wiki articles found