PDA

View Full Version : Slot not getting called, Qt::ConnectionType, Thread



StarShaper
7th February 2012, 02:29
I have some strange problems with one SIGNAL/SLOT.

There is one class A::B::Class1 that emits two signals, first without argument, second with one argument.


A::B::J param;
emit orange(param); // Not executed
emit blue();

In A::C::Class2 the signals and slots are connected. Both connections returns true, but only 1 Slot gets executed, that one without any parameter.


void V::run()
{
object = new Object();

connect(object, SIGNAL(blue()), this, SLOT(blue_exec()));
connect(object, SIGNAL(orange(A::B::J&)), this, SLOT(orange_exec(A::B::J&)));

//...

exec();
}

It is definately a problem with the SIGNAL.

I just did a test with Qt::ConnectionType and a test allocating object on stack with Object object and


void V::run()
{
Object object;

connect(&object, SIGNAL(orange(A::B::J&)), this, SLOT(orange_exec(A::B::J&)));

//...

exec();
}

It works. Same thing, if I use Qt::DirectConnection.


void V::run()
{
object = new Object();

connect(object, SIGNAL(orange(A::B::J&)), this, SLOT(orange_exec(A::B::J&)), Qt::DirectConnection);

//...

exec();
}

That doesn't make sense to me. Why the first connection gets executed, while the second does not. Both are using the same "object"?

:confused:

ChrisW67
7th February 2012, 05:27
Look in the output of your program for warnings like:


QObject::connect: Cannot queue arguments of type 'A::B::J&'
(Make sure 'A::B::J&' is registered using qRegisterMetaType().)

You will not be able to queue a reference though.

MarekR22
7th February 2012, 09:22
if it is a const reference then he can to queue it, but he have to provide meta data for that type of reference.
Not const reference requires Blocking Queued Connection.
See:
http://developer.qt.nokia.com/doc/qt-4.8/threads-qobject.html#signals-and-slots-across-threads
http://developer.qt.nokia.com/doc/qt-4.8/qt.html#ConnectionType-enum
http://developer.qt.nokia.com/doc/qt-4.8/qmetatype.html#qRegisterMetaType

StarShaper
7th February 2012, 14:04
A::B::J& works! It is registered. But the Signal only works, if object is created in the run() method with Object object;

Read the second part of my posting.

And it also works, if I append Qt::DirectConnection.

This is really strange!

Must be some kind of threading issue. :confused:

@MarekR22: I'm aware of the threading issues with Connection. But it doesn't make sense to me in my example. Both objects are from the same thread.

Added after 11 minutes:


A::B::J& works! It is registered. But the Signal only works, if object is created in the run() method with Object object;

Read the second part of my posting.

And it also works, if I append Qt::DirectConnection.

This is really strange!

Must be some kind of threading issue. :confused:

@MarekR22: I'm aware of the threading issues with Connection. But it doesn't make sense to me in my example. Both objects are from the same thread.

Yes, it works also with qRegisterMetaType();

If is is a const reference and if I do:


qRegisterMetaType<A::B::J>("A::B::J");
connect(object, SIGNAL(orange(const A::B::J&)), this, SLOT(orange_exec(const A::B::J&)));