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

QVariantList lessThan operator via QVariant is broken

XMLWordPrintable

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

      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.

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

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

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes