[Qt-interest] Q_DECLARE_METATYPE, qRegisterType, and threads...
BRM
bm_witness at yahoo.com
Wed Nov 17 22:35:54 CET 2010
I recently wrote about changing my threading model from using a QThread derived
class to just using straight QThreads and moving objects to them.
Well, I now have a program where I do just that - for the worker thread it just
creates the object and move it to a thread.
However, I am now running into a problem with one of my custom types - an enum -
that I use in a signal for logging information back to a central log - e.g.
syslog.
When the object in the new thread goes to emit the signal, I get the message
that the enum is not registered:
QObject::connect: Cannot queue arguemtns for type 'yourEnum' (make sure
'yourEnum' is registered using qRegisterType().)
Problem is, I've declared it several ways that should make it valid to the
meta-object system:
yourEnum {
...
};
Q_DECLARE_METATYPE(yourEnum)
Q_ENUMS(yourEnum)
...
Note: The above is _not_ in a class definition but a shared header.
In other locations I have worked around this by making sure I register these
custom types in the run() method - so it's registered in the thread on first
use. (Otherwise it always complained about not being defined.)
However, I don't have any kind of method here to do that - the first thing that
gets called in the thread's object is something to handle data - it doesn't
create/destroy anything in the new thread until then.
What am I doing wrong?
TIA,
Ben
More information about the Qt-interest-old
mailing list