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

From Qt Wiki
Jump to navigation Jump to search

Template:ArticleMetaData

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]


Header[edit | edit source]

  1. 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]


Postconditions[edit | edit source]

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