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

Cannot use std::sort on a QJsonArray

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P3: Somewhat important
    • None
    • 5.4.1
    • Core: Other
    • None
    • Ubuntu 14.04 x64
      gcc 4.8.2
      Qt 5.4.1

    Description

      I have a QJsonArray that only contains strings. When I try to use std::sort on the array, I get a compiler error message stating it could not find a swap function with the signature swap(QJsonValueRef, QJsonValueRef).

      Example:

      QJsonArray array;
      array.append(QString("v1"));
      array.append(QString("v2"));
      std::sort(array.begin(), array.end(), [](QJsonValue &v1, QJsonValue &v2){
          return v1.toString() < v2.toString();
      });
      

      Gcc Error Message:

      no matching function for call to 'swap(QJsonValueRef, QJsonValueRef)'
             swap(*__a, *__b);
      

      My work around was to write the following code in a global header file:

      inline void swap(QJsonValueRef v1, QJsonValueRef v2)
      {
          QJsonValue temp(v1);
          v1 = QJsonValue(v2);
          v2 = temp;
      }
      

      Ideally, this function should live below the definition of QJsonValueRef.

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            kreios4004 Keith Gardner
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes