×
Namespaces

Variants
Actions

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

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia 5800 XpressMusic
Compatibility
Platform(s): S60 3rd Edition, FP1, FP2
S60 5th Edition
Symbian
Article
Keywords: QThread, qRegisterMetaType, Q_DECLARE_METATYPE
Created: tepaa (20 May 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Overview

This code snippet demonstrates how to use your own class as a signal and slot parameter in QThread.

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.

This page was last modified on 11 October 2012, at 04:18.
81 page views in the last 30 days.
×