Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-116677

QVariantList lessThan operator via QVariant is broken

    XMLWordPrintable

Details

    • Bug
    • Resolution: Won't Do
    • Not Evaluated
    • None
    • 5.15.0
    • None
    • Windows

    Description

      Executing the following code triggers an assert:

      #include <QVariantList>
      #include <cassert>
      
      int main() {
           QVariantList l0;
           QVariantList l1;
           l0 << 1 << 2;
           l1 << 1 << 3;
      
           // this works as expected
           assert((l0 == l1) == (l1 == l0));
           assert((l0 < l1) != (l1 < l0));
           assert((l0 > l1) != (l1 > l0));
      
           // here things get interesting
           QVariant v0(l0);
           QVariant v1(l1);
           assert((v0 == v1) == (v1 == v0));
           assert((v0 < v1) != (v1 < v0));  //< assert!
           assert((v0 > v1) != (v1 > v0));  //< assert!
      
          return 0;
      }
      

      I'd expect the QVariant::operator< to call the operator of the contained QVariantList which in turn compares its contents.
      I can work around the issue by wrapping QVariant in a custom class that implements the lessThan-operator, or by using containers with custom comparators. Nonetheless, I think this should be addressed...

       

      note: I could only test this in Qt 5.9.7 on windows, but the same effect manifests itself under Qt5.15 on MacOS.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            schoebey roman
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes