PDA

View Full Version : qRegisterMetaType vs. uint64



tuli
22nd November 2012, 15:10
Hi!

I just noticed that the Qt meta system wont accept unsinged 64bit integers in its signal/slot calling system.
I am trying to connect a slot with a signal, both of type


void testtest(uint64 t);


uint64 is a typedef for 64 bit integers in VS:


typedef unsigned __int64 uint64;

the connect() call returns true, but when the signal is emitted, Qt outputs this:


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


Hm. I would have assumed uint64 to be covered, but oh well, i added this right after the typedef:


Q_DECLARE_METATYPE(uint64)

Everything compiles fine, the connect() call succeeds - but when i emmit the signal, Qt errors out again with above message.


Help? :(

wysota
22nd November 2012, 16:48
Qt performs char by char comparison of type names thus you can't use typedefs or defines, the names have to match literally (both in the connect statement and in signal/slot prototypes).

amleto
22nd November 2012, 17:13
To use the type T in QVariant, using Q_DECLARE_METATYPE() is sufficient. To use the type T in queued signal and slot connections, qRegisterMetaType<T>() must be called before the first connection is established.

http://doc.qt.digia.com/qt/qmetatype.html#qRegisterMetaType-2

tuli
23rd November 2012, 07:47
Ok, thanks.

Based on above link, i a m now calling


int id = qRegisterMetaType<uint64>();

right before my connect() call. Doesnt change anything, though. :(
The returned value in "id" is 5.

"quint64" is registered properly already and works. However, i`d really like to get this to work with custom types... :)

wysota
23rd November 2012, 09:12
Show us your exact connect statement and signal and slot declarations.

tuli
23rd November 2012, 10:05
signals:
void ItChange(uint64 n);


public slots:
void OnItChange(uint64 n);


int id = qRegisterMetaType<uint64>(); //returns 5
connect(pl, SIGNAL(ItChange(uint64)), zu, SLOT(OnItChange(uint64))); //returns true

wysota
23rd November 2012, 14:04
Do pl and zu live in different threads?

tuli
23rd November 2012, 15:19
potentially, yes. i hadnt considered that to be much of a problem, because built-in data types like quint64 work fine.

wysota
23rd November 2012, 15:29
It's not about "potentially". If those objects live in the same thread, in normal conditions you shouldn't be seeing the message about uint64 being unregistered. Therefore it is important to establish whether they are in different threads or not. It would be best if you prepared a minimal compilable example reproducing the problem.

tuli
23rd November 2012, 15:54
not on my developing machine this weekend, but yes they are in two different threads.
i`ll provide an example later on monday.

anda_skoa
24th November 2012, 10:57
You could try to reduce the example by putting a value of that type into a QVariant.
Ultimately this is what happens to signal arguments in a cross-thread connection.

something like



uint64 i = 1234;
QVariant v = QVariant::fromValue<uint64>( i );


Cheers,
_

wysota
24th November 2012, 13:44
He could just use quint64 :)