How to test if type of data emitted by signal is quint8 using QSignalSpy?
-
Using Qt 5.4.x
QVariant::type()(still?) doesn't support basic C++ (and their respective Qttypedefs) so the following will always fail:Obj* o = new Obj(); // A class that contains signalFoo(quint8) QSignalSpy* oS = new QSignalSpy(o, SIGNAL(signalFoo(quint8))); // Trigger signalFoo(quint8) QCOMPARE(this->oS->count(), 1); QList<QVariant> oSArgs = this->oS->takeFirst(); QVERIFY(oSArgs->at(0).type() == QVariant::UInt);The same applies if I use
QVariant::Char.So my question is how exactly am I supposed to test the type of the returned data if the type is not supported?
UIntstands forunsigned int(as perQMetaType::UInt), which is 4 bytes and not 1 that thequint8stands for.I know that in the case above it's not actually required if I have just a single
signalthat the instance ofObjcan emit but still it's something I'd like to know. -
Hi,
Out of curiosity, why do you need to test the datatype ?
-
I wanted to make sure that if someone changes my code (the value range of the data carried by that signal; for example from quint8 to quint16) the respective unit test will detect this and fail. On multiple occasions I had to waste several hours hunting down bugs related to generating a numeric value with one range and then silently converting it to another (less accurate or with a different (usually smaller) value range).
It's not that necessary but since I gave it a shot and found out that
QVariantdoesn't support it I decided to ask here. :)