Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date
All threads index page 3

Qt-interest Archive, February 2007
Signals between Threads


Message 1 in thread

Hi Trolls,

I'm trying to connect a signal from a thread, passing a QUuid to a slot in the 
main thread in a QCoreApplication. When calling the "connect" the following 
message appears in the console and i'm quite out of ideas.

QObject::connect: Cannot queue arguments of type 'QUuid'
(Make sure 'QUuid' is registed using qRegisterMetaType().)

I'm using this Quuid to determine which thread has a new networkconnection.
The signal is emitted from an object in the thread and is connected to an 
object in the main thread.

Is this possible or am I missing something?
-- 
 [ signature omitted ] 

Message 2 in thread

Peter M. Groen wrote:
> Hi Trolls,
>
> I'm trying to connect a signal from a thread, passing a QUuid to a slot in the 
> main thread in a QCoreApplication. When calling the "connect" the following 
> message appears in the console and i'm quite out of ideas.
>
> QObject::connect: Cannot queue arguments of type 'QUuid'
> (Make sure 'QUuid' is registed using qRegisterMetaType().)
>
> I'm using this Quuid to determine which thread has a new networkconnection.
> The signal is emitted from an object in the thread and is connected to an 
> object in the main thread.
>
> Is this possible or am I missing something?
>   
The error is quite correct. it's telling you that the metatype-system
doesn't know how to convert a quuid to a qvariant/void and back again,
which is necessary to the internal signalling system. Read the help  on
qRegisterMetaType, and it'll give you information on how to register the
type to the metatype system.

-- 
 [ signature omitted ] 

Message 3 in thread

On Monday 12 February 2007 23:35, Bill KING wrote:
> Peter M. Groen wrote:
> > Hi Trolls,
> >
> > I'm trying to connect a signal from a thread, passing a QUuid to a slot
> > in the main thread in a QCoreApplication. When calling the "connect" the
> > following message appears in the console and i'm quite out of ideas.
> >
> > QObject::connect: Cannot queue arguments of type 'QUuid'
> > (Make sure 'QUuid' is registed using qRegisterMetaType().)
> >
> > I'm using this Quuid to determine which thread has a new
> > networkconnection. The signal is emitted from an object in the thread and
> > is connected to an object in the main thread.
> >
> > Is this possible or am I missing something?
>
> The error is quite correct. it's telling you that the metatype-system
> doesn't know how to convert a quuid to a qvariant/void and back again,
> which is necessary to the internal signalling system. Read the help  on
> qRegisterMetaType, and it'll give you information on how to register the
> type to the metatype system.

So if what you are saying is correct, by converting my QUuid to a QString and 
a QVariant after that, I'll be able to do it also? (It is a bit of a hack, I 
know, but I read the documentation on qRegisterMetaType and quite frankly, I 
didn't understand it... :S

-- 
 [ signature omitted ] 

Message 4 in thread

On 2/12/07, Peter M. Groen <pgroen@xxxxxxxx> wrote:
> On Monday 12 February 2007 23:35, Bill KING wrote:
> > Peter M. Groen wrote:
> > > Hi Trolls,
> > >
> > > I'm trying to connect a signal from a thread, passing a QUuid to a slot
> > > in the main thread in a QCoreApplication. When calling the "connect" the
> > > following message appears in the console and i'm quite out of ideas.
> > >
> > > QObject::connect: Cannot queue arguments of type 'QUuid'
> > > (Make sure 'QUuid' is registed using qRegisterMetaType().)
> > >
> > > I'm using this Quuid to determine which thread has a new
> > > networkconnection. The signal is emitted from an object in the thread and
> > > is connected to an object in the main thread.
> > >
> > > Is this possible or am I missing something?
> >
> > The error is quite correct. it's telling you that the metatype-system
> > doesn't know how to convert a quuid to a qvariant/void and back again,
> > which is necessary to the internal signalling system. Read the help  on
> > qRegisterMetaType, and it'll give you information on how to register the
> > type to the metatype system.
>
> So if what you are saying is correct, by converting my QUuid to a QString and
> a QVariant after that, I'll be able to do it also? (It is a bit of a hack, I
> know, but I read the documentation on qRegisterMetaType and quite frankly, I
> didn't understand it... :S

From the documentation (http://doc.trolltech.com/4.2/qmetatype.html):

"Call qRegisterMetaType() to make type available to non-template based
functions, such as the queued signal and slot connections."

and:

"Any class or struct that has a public default constructor, a public
copy constructor, and a public destructor can be registered."

All you need to do is call qRegisterMetaType("QUuid"). No conversion
to QVariant necessary.

-- 
 [ signature omitted ] 

Message 5 in thread

On Monday 12 February 2007 23:46, Andrew Medico wrote:

> >From the documentation (http://doc.trolltech.com/4.2/qmetatype.html):
>
> "Call qRegisterMetaType() to make type available to non-template based
> functions, such as the queued signal and slot connections."
>
> and:
>
> "Any class or struct that has a public default constructor, a public
> copy constructor, and a public destructor can be registered."
>
> All you need to do is call qRegisterMetaType("QUuid"). No conversion
> to QVariant necessary.

Bill and Andrew,

Thanks a lot for your explanation. I think I get it now :)
I'll go try.

-- 
 [ signature omitted ] 

Message 6 in thread

Peter M. Groen wrote:
> On Monday 12 February 2007 23:35, Bill KING wrote:
>   
>> Peter M. Groen wrote:
>>     
>>> Hi Trolls,
>>>
>>> I'm trying to connect a signal from a thread, passing a QUuid to a slot
>>> in the main thread in a QCoreApplication. When calling the "connect" the
>>> following message appears in the console and i'm quite out of ideas.
>>>
>>> QObject::connect: Cannot queue arguments of type 'QUuid'
>>> (Make sure 'QUuid' is registed using qRegisterMetaType().)
>>>
>>> I'm using this Quuid to determine which thread has a new
>>> networkconnection. The signal is emitted from an object in the thread and
>>> is connected to an object in the main thread.
>>>
>>> Is this possible or am I missing something?
>>>       
>> The error is quite correct. it's telling you that the metatype-system
>> doesn't know how to convert a quuid to a qvariant/void and back again,
>> which is necessary to the internal signalling system. Read the help  on
>> qRegisterMetaType, and it'll give you information on how to register the
>> type to the metatype system.
>>     
>
> So if what you are saying is correct, by converting my QUuid to a QString and 
> a QVariant after that, I'll be able to do it also? (It is a bit of a hack, I 
> know, but I read the documentation on qRegisterMetaType and quite frankly, I 
> didn't understand it... :S
>
>   
No, the metatype system needs to have an id associated with it, hence
the need for registration. The metatype system is what passes the
information around internally to and from the signalling system. It's
the system that gives signals and slots it's power by allowing
genericness, ie, it can take an id for a signal on a class id, and a
list of ids for parameter types, and that's all that it needs to know
about that signal. It can queue it up for later, it can allow you to
call it dynamically by invoke, etc etc etc, so...

in your header file,
Q_DECLARE_METATYPE(QUuid);
and in your startup routines/an early class constructor:
qRegisterMetaType<QUuid>();

or alternately, somewhere in your startup code:
qRegisterMetaType<QUuid>("QUuid");

That should be all that's needed.

-- 
 [ signature omitted ] 

Message 7 in thread

On 13.02.07 08:48:55, Bill KING wrote:
> Peter M. Groen wrote:
> > On Monday 12 February 2007 23:35, Bill KING wrote:
> >> The error is quite correct. it's telling you that the metatype-system
> >> doesn't know how to convert a quuid to a qvariant/void and back again,
> >> which is necessary to the internal signalling system. Read the help  on
> >> qRegisterMetaType, and it'll give you information on how to register the
> >> type to the metatype system.
> >
> > So if what you are saying is correct, by converting my QUuid to a QString and 
> > a QVariant after that, I'll be able to do it also? (It is a bit of a hack, I 
> > know, but I read the documentation on qRegisterMetaType and quite frankly, I 
> > didn't understand it... :S
> >   
> No, the metatype system needs to have an id associated with it, hence
> the need for registration.

Uhm, of course it would work if Peter turns his QUuid into a QString and
transports that instead of the QUuid directly. I guess you misunderstood
that.

Andreas

-- 
 [ signature omitted ] 

Message 8 in thread

On Tuesday 13 February 2007 00:01, Andreas Pakulat wrote:
> On 13.02.07 08:48:55, Bill KING wrote:
> > Peter M. Groen wrote:
> > > On Monday 12 February 2007 23:35, Bill KING wrote:
> > >> The error is quite correct. it's telling you that the metatype-system
> > >> doesn't know how to convert a quuid to a qvariant/void and back again,
> > >> which is necessary to the internal signalling system. Read the help 
> > >> on qRegisterMetaType, and it'll give you information on how to
> > >> register the type to the metatype system.
> > >
> > > So if what you are saying is correct, by converting my QUuid to a
> > > QString and a QVariant after that, I'll be able to do it also? (It is a
> > > bit of a hack, I know, but I read the documentation on
> > > qRegisterMetaType and quite frankly, I didn't understand it... :S
> >
> > No, the metatype system needs to have an id associated with it, hence
> > the need for registration.
>
> Uhm, of course it would work if Peter turns his QUuid into a QString and
> transports that instead of the QUuid directly. I guess you misunderstood
> that.
>
> Andreas

Pfew! Thanx Andreas. I tried calling qRegisterMetaType( "QUuid" ) but my 
compiler throws up with..

/usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h: In static member 
function âstatic int QMetaTypeId2<T>::qt_metatype_id() [with T = const 
char]â:
/usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h:176:   instantiated 
from âint qMetaTypeId(T*) [with T = const char]â
/usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h:186:   instantiated 
from âint qRegisterMetaType(T*) [with T = const char]â
CSocketManager.cpp:20:   instantiated from here
/usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h:166: 
error: âqt_metatype_idâ is not a member of âQMetaTypeId<const char>â

And that got me back to square one again.. :( I'll try the "convert" thing..

-- 
 [ signature omitted ] 

Message 9 in thread

Peter M. Groen wrote:
> On Tuesday 13 February 2007 00:01, Andreas Pakulat wrote:
>   
>> On 13.02.07 08:48:55, Bill KING wrote:
>>     
>>> Peter M. Groen wrote:
>>>       
>>>> On Monday 12 February 2007 23:35, Bill KING wrote:
>>>>         
>>>>> The error is quite correct. it's telling you that the metatype-system
>>>>> doesn't know how to convert a quuid to a qvariant/void and back again,
>>>>> which is necessary to the internal signalling system. Read the help 
>>>>> on qRegisterMetaType, and it'll give you information on how to
>>>>> register the type to the metatype system.
>>>>>           
>>>> So if what you are saying is correct, by converting my QUuid to a
>>>> QString and a QVariant after that, I'll be able to do it also? (It is a
>>>> bit of a hack, I know, but I read the documentation on
>>>> qRegisterMetaType and quite frankly, I didn't understand it... :S
>>>>         
>>> No, the metatype system needs to have an id associated with it, hence
>>> the need for registration.
>>>       
>> Uhm, of course it would work if Peter turns his QUuid into a QString and
>> transports that instead of the QUuid directly. I guess you misunderstood
>> that.
>>
>> Andreas
>>     
>
> Pfew! Thanx Andreas. I tried calling qRegisterMetaType( "QUuid" ) but my 
> compiler throws up with..
>
> /usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h: In static member 
> function âstatic int QMetaTypeId2<T>::qt_metatype_id() [with T = const 
> char]â:
> /usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h:176:   instantiated 
> from âint qMetaTypeId(T*) [with T = const char]â
> /usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h:186:   instantiated 
> from âint qRegisterMetaType(T*) [with T = const char]â
> CSocketManager.cpp:20:   instantiated from here
> /usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h:166: 
> error: âqt_metatype_idâ is not a member of âQMetaTypeId<const char>â
>
> And that got me back to square one again.. :( I'll try the "convert" thing..
>
>   
(grar, re-sending to all, reply-to gets me every time).

Go back and read my last example, plus the examples in the help file,
qRegisterMetaType<QUuid>("QUuid"), and you'll find it compiles. it's the filling in of the template bit that provides all the power.

Andreas, true true, but if we can teach him to fish...  :) 


-- 
 [ signature omitted ] 

Message 10 in thread

On Monday 12 February 2007 23:29, Peter M. Groen wrote:
> Hi Trolls,
>
> I'm trying to connect a signal from a thread, passing a QUuid to a slot in
> the main thread in a QCoreApplication. When calling the "connect" the
> following message appears in the console and i'm quite out of ideas.
>
> QObject::connect: Cannot queue arguments of type 'QUuid'
> (Make sure 'QUuid' is registed using qRegisterMetaType().)
>
> I'm using this Quuid to determine which thread has a new networkconnection.
> The signal is emitted from an object in the thread and is connected to an
> object in the main thread.
>
> Is this possible or am I missing something?

Ok. In the main Class of the library where this happens, adding the following 
to the constructor solved it:


// Register types for Signal / Slot handling
qRegisterMetaType<QUuid>( "QUuid" );
qRegisterMetaType<QAbstractSocket*>( "QAbstractSocket*" );
qRegisterMetaType<socketType>( "socketType" );


Thank you all for answering my (Obviously stupid) questions.
-- 
 [ signature omitted ] 

Message 11 in thread

On Tuesday 13 February 2007 01:21, Peter M. Groen wrote:
> Ok. In the main Class of the library where this happens, adding the
> following to the constructor solved it:
>
> qRegisterMetaType<QAbstractSocket*>( "QAbstractSocket*" );

Just an FYI, you don't have to register pointers, since Qt will do the right 
thing with them. You only need to register your custom value types.

-- 
 [ signature omitted ] 

Message 12 in thread

On Tuesday 13 February 2007 07:20, Bradley T Hughes wrote:
> On Tuesday 13 February 2007 01:21, Peter M. Groen wrote:
> > Ok. In the main Class of the library where this happens, adding the
> > following to the constructor solved it:
> >
> > qRegisterMetaType<QAbstractSocket*>( "QAbstractSocket*" );
>
> Just an FYI, you don't have to register pointers, since Qt will do the
> right thing with them. You only need to register your custom value types.

Hi Bradley,

That's what I expected, yes, but runtime it complains when I don't register 
it.. It doesn't hurt to do it, so...

But thank you for your pointers. I appreciate it and learned a lot.

-- 
 [ signature omitted ] 

Message 13 in thread

Forwarded from own mailbox..

----------  Forwarded Message  ----------

Subject: Re: Signals between Threads
Date: Tuesday 13 February 2007 00:11
From: Bill KING <bill.king@xxxxxxxxxxxxx>
To: "Peter M. Groen" <pgroen@xxxxxxxx>

Peter M. Groen wrote:
> On Tuesday 13 February 2007 00:01, Andreas Pakulat wrote:
>> On 13.02.07 08:48:55, Bill KING wrote:
>>> Peter M. Groen wrote:
>>>> On Monday 12 February 2007 23:35, Bill KING wrote:
>>>>> The error is quite correct. it's telling you that the metatype-system
>>>>> doesn't know how to convert a quuid to a qvariant/void and back again,
>>>>> which is necessary to the internal signalling system. Read the help
>>>>> on qRegisterMetaType, and it'll give you information on how to
>>>>> register the type to the metatype system.
>>>>
>>>> So if what you are saying is correct, by converting my QUuid to a
>>>> QString and a QVariant after that, I'll be able to do it also? (It is a
>>>> bit of a hack, I know, but I read the documentation on
>>>> qRegisterMetaType and quite frankly, I didn't understand it... :S
>>>
>>> No, the metatype system needs to have an id associated with it, hence
>>> the need for registration.
>>
>> Uhm, of course it would work if Peter turns his QUuid into a QString and
>> transports that instead of the QUuid directly. I guess you misunderstood
>> that.
>>
>> Andreas
>
> Pfew! Thanx Andreas. I tried calling qRegisterMetaType( "QUuid" ) but my
> compiler throws up with..
>
> /usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h: In static member
> function ÃÂÂstatic int QMetaTypeId2<T>::qt_metatype_id() [with T = const
> char]ÃÂÂ:
> /usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h:176:  
> instantiated from ÃÂÂint qMetaTypeId(T*) [with T = const char]ÃÂÂ
> /usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h:186:  
> instantiated from ÃÂÂint qRegisterMetaType(T*) [with T = const char]ÃÂÂ
> CSocketManager.cpp:20:   instantiated from here
> /usr/local/Trolltech/Qt-4.2.2/include/QtCore/qmetatype.h:166:
> error: ÃÂÂqt_metatype_idÃÂÂ is not a member of ÃÂÂQMetaTypeId<const
> char>ÃÂÂ
>
> And that got me back to square one again.. :( I'll try the "convert"
> thing..

Go back and read my last, plus the examples in the help file,
qRegisterMetaType<QUuid>("QUuid").

Andreas, true true, but if we can teach him to fish... :)

--
 [ signature omitted ] 

Message 14 in thread

On Tuesday 13 February 2007 00:13, Bill wrote:
>
> Go back and read my last, plus the examples in the help file,
> qRegisterMetaType<QUuid>("QUuid").
>
> Andreas, true true, but if we can teach him to fish... :)
>
> --
> Bill King, Software Engineer
> Trolltech, Brisbane Technology Park
> 26 Brandl St, Eight Mile Plains,
> QLD, Australia, 4113
> Tel + 61 7 3219 9906 (x137)
> Fax + 61 7 3219 9938
> mobile: 0423 532 733
>
> -------------------------------------------------------

Right. That was what I was missing. I'll not catch big one's yet, Bill, but 
I'm willing to learn. And before my hook is of the professional type, I'll 
use a safety pin instead ;)

Thanx mates. Got it working now.

-- 
 [ signature omitted ]