[Development] QVariant comparison in Qt6

Lars Knoll lars.knoll at qt.io
Tue Sep 22 07:55:16 CEST 2020


On 21 Sep 2020, at 23:02, Thiago Macieira <thiago.macieira at intel.com<mailto:thiago.macieira at intel.com>> wrote:

On Monday, 21 September 2020 01:17:58 PDT Lars Knoll wrote:
On 18 Sep 2020, at 17:11, Thiago Macieira <thiago.macieira at intel.com<mailto:thiago.macieira at intel.com>>
wrote:

On Friday, 18 September 2020 06:48:50 PDT Lars Knoll wrote:

std::optional<int> QVariant::compare(const QVariant &other);

Would that be good enough?


Why the optional?


Because there is no valid comparison we could do between a QDate and a
QPoint. And because a QPolygon doesn’t provide any ordering even when
comparing two of them.

Then we don't need the optional, we just need a distinct value from the other
three. In my other email, I gave you three options.

I did choose optional because it nicely expressed the unordered state (and forces you to acknowledge it), and kept the -1/0/+1 states we use in compare for the rest of Qt.

I do not want to simply return an int, as the risk that people ignore the  Unordered state it too big with that. So the other choice would be to add an enum in the Qt namespace (as I need this for QMetaType as well, which currently has a std::optional<int> compare()).

Cheers,
Lars

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20200922/bccd61d1/attachment-0001.html>


More information about the Development mailing list