PDA

View Full Version : QObject::connect: Cannot queue arguments of type 'MyStruct'



navid
28th March 2010, 15:53
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 ...
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
///////////////////

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>)

class MyThread: public QThread
{
Q_OBJECT
...
}
...
//////////




mythread.cpp
//////////////////

#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)));

...

}

/////////////////

where is the problem?

Lykurg
28th March 2010, 16:31
QObject::connect: Cannot queue arguments of type 'MyStruct'
(Make sure 'MyStruct' is registered using qRegisterMetaType().)
[...]
where is the problem?
Hmmm, where did you qRegisterMetaType your struct? I can't see that in your pasted code. And did you realize that [QTCLASS] is not the right tag for formatting source code?

navid
28th March 2010, 16:40
sorry, I edited it

Lykurg
28th March 2010, 17:13
Did you try register MyStruct in your main function like
qRegisterMetaType<MyStruct>("MyStruct");?

navid
28th March 2010, 17:22
what do you mean with "main function"?

navid
28th March 2010, 17:26
thanks
you are right