Qt Forum

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

    Unsolved QCOMPARE requires explicit casting to handle properly comparison between quint and some number

    General and Desktop
    2
    2
    654
    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

      I'm wondering if this is made on purpose or is a bug but the following line

       quint16 num = 0;
       QCOMPARE(num, 0);
      

      cannot be compiled and the error

      undefined reference to `bool QTest::qCompare<unsigned short, int>(unsigned short const&, int const&, char const*, char const*, char const*, int)'

      appears.

      However if I do

      QCOMPARE(num, quint16(0));
      

      everything compiles just fine. I do realize that by forcing the tester to do explicit casting he is forced to check the value that he is actually entering (if we have quint8 for example and compare it to 1000, this clearly introduces a problem) but on the other hand every single time the tester needs to make trivial comparisons he needs to typecast.

      Also the behaviour above is easily avoided by simply replacing QCOMPARE with QVERIFY like so

      QVERIFY((num == 0) == true);
      
      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        What version of Qt are you using ?
        With which compiler ?
        On what OS ?

        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 0
        • First post
          Last post