hi,
I always after application running, receive debug text of:
QObject::connect: Cannot queue arguments of type 'MyStruct'
(Make sure 'MyStruct' is registered using qRegisterMetaType().)
I have defined MyStruct in an accessible header file:
myheader.h
////////////////////
#ifndef MYHEADER_H
#define MYHEADER_H
#include <QObject>
#include <QMetaType>
struct MyStruct
{
int ...
double ...
MyStruct(...) :
...
{}
MyStruct operator=(const MyStruct& tother)
{
...
return *this;
}
bool operator!=(const MyStruct& tother)
{
...
}
};
Q_DECLARE_METATYPE(MyStruct)
{
Q_OBJECT
...
}
#endif // MYHEADER_H
#ifndef MYHEADER_H
#define MYHEADER_H
#include <QObject>
#include <QMetaType>
struct MyStruct
{
int ...
QString ...
double ...
MyStruct(...) :
...
{}
MyStruct operator=(const MyStruct& tother)
{
...
return *this;
}
bool operator!=(const MyStruct& tother)
{
...
}
};
Q_DECLARE_METATYPE(MyStruct)
class MyHeader: public QObject
{
Q_OBJECT
...
}
#endif // MYHEADER_H
To copy to clipboard, switch view to plain text mode
///////////////////
and I have used it in a thread:
mythread.h
////////////
...
#include <QThread>
#include "myheader.h"
#include <QMetaType>
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QList<MyStruct>)
{
Q_OBJECT
...
}
...
...
#include <QThread>
#include "myheader.h"
#include <QMetaType>
Q_DECLARE_METATYPE(QList<int>)
Q_DECLARE_METATYPE(QList<MyStruct>)
class MyThread: public QThread
{
Q_OBJECT
...
}
...
To copy to clipboard, switch view to plain text mode
//////////
mythread.cpp
//////////////////
#include "mythread.h"
MyThread
::MyThread(QObject *parent
):{
}
MyThread::~MyThread()
{
}
void MyThread::run()
{
qRegisterMetaType<QList<int> >();
qRegisterMetaType< QList<MyStruct> >();
ThreadReceiverObject * my_reciever = new ThreadReceiverObject();
QObject::connect(otherthread,
SIGNAL(sigReqSchedule
(QList<MyStruct>, QList<int>,
int)),
my_reciever,SLOT(onReqSchedule(QList<MyStruct>, QList<int>, int)));
...
}
#include "mythread.h"
MyThread::MyThread(QObject *parent):
QThread(parent)
{
}
MyThread::~MyThread()
{
}
void MyThread::run()
{
qRegisterMetaType<QList<int> >();
qRegisterMetaType< QList<MyStruct> >();
ThreadReceiverObject * my_reciever = new ThreadReceiverObject();
QObject::connect(otherthread,SIGNAL(sigReqSchedule(QList<MyStruct>, QList<int>, int)),
my_reciever,SLOT(onReqSchedule(QList<MyStruct>, QList<int>, int)));
...
}
To copy to clipboard, switch view to plain text mode
/////////////////
where is the problem?
Bookmarks