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. QCOMPARE requires explicit casting to handle properly comparison between quint and some number
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 976 Views 1 Watching
  • 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

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

      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
      0

      • Login

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