You Are Here:

Community: Wiki

This page was last modified on 3 September 2009, at 07:40.

CS001428 - Using your own class as a signal and slot parameter in QThread

From Forum Nokia Wiki


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

Overview

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.


Preconditions


Header

#include "MyError.h"
 
public slots:
void receiveError(MyError*);


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

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)


See also


Postconditions

Your own data class can be used as a signal and slot parameter in QThread.

Related Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia