Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to test if type of data emitted by signal is quint8 using QSignalSpy?

    General and Desktop
    3
    4
    483
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Red Baron last edited by

      Using Qt 5.4.x

      QVariant::type() (still?) doesn't support basic C++ (and their respective Qt typedefs) 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? UInt stands for unsigned int (as per QMetaType::UInt), which is 4 bytes and not 1 that the quint8 stands for.

      I know that in the case above it's not actually required if I have just a single signal that the instance of Obj can emit but still it's something I'd like to know.

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Out of curiosity, why do you need to test the datatype ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 1
        • R
          Red Baron last edited by

          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 QVariant doesn't support it I decided to ask here. :)

          1 Reply Last reply Reply Quote 0
          • VRonin
            VRonin last edited by

            It's much easier that you think. oS->isValid() will return false if someone changes the argument of signalFoo to anything other than quint8

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            1 Reply Last reply Reply Quote 0
            • First post
              Last post