[Interest] QVariant compare operator

Yves Maurischat yves.maurischat at basyskom.com
Mon Apr 20 09:16:27 CEST 2020


Hi Yuri,

I assume you're implementing a QSortFilterProxyModel for sorting and 
filtering: you can reimplement QSortFilterProxyModel::lessThan() 
<https://doc.qt.io/qt-5/qsortfilterproxymodel.html#lessThan>. Basically 
you'll do the following (in pseudo code):

bool  YourSortModel::lessThan(constQModelIndex <https://doc.qt.io/qt-5/qmodelindex.html>  &/source_left/, constQModelIndex <https://doc.qt.io/qt-5/qmodelindex.html>  &/source_right/)
{
     auto left =/source_left.data(someRole);/
     auto right=/source_right//.data(///someRole/);/

     return (left.toByteArray() < right.toByteArray());
}



Mit freundlichen Grüßen | Kind regards,

*Yves Maurischat*
Senior Software Engineer

basysKom GmbH
Robert-Bosch-Str. 7 | 64293 Darmstadt | Germany
Tel: +49 6151 870 589 -144 | Fax: -199
yves.maurischat at basyskom.com | www.basyskom.com

Handelsregister: Darmstadt HRB 9352
Geschaeftsfuehrende Partner: Heike Ziegler, Alexander Sorg


Am 18.04.2020 um 11:43 schrieb evilruff:
> Hi Thiago,
>
> I am happy ro redesign my code, but how then sorting/filtering models 
> will work? As data() returns QVariant. Or you plan to use setSorting 
> based on lambda's and std::function to provide strict types sorting?
>
> And what if from API point of view user want just to specify column 
> without aware of data types.
>
> Am I missing something? Woukd really appreceate if you can point me to 
> some direction to look at.
>
>
> Regards,
> Yuri
>
>
> Relational comparisons with QVariant are deprecated in 5.15 and will be
> removed because they are a misfeaure. Redesign your code so your 
> question does
> not need to be asked.
>
>
>
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200420/ac7933d4/attachment.html>


More information about the Interest mailing list