Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to test if type of data emitted by signal is quint8 using QSignalSpy?
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 766 Views
  • 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 Offline
    R Offline
    Red Baron
    wrote on last edited by
    #1

    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
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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
      1
      • R Offline
        R Offline
        Red Baron
        wrote on last edited by
        #3

        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
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          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
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved