c++ - Comparing Items in QList qt5.3 -
c++ - Comparing Items in QList qt5.3 -
i trying compare items in qlist. here old way using qptrcollection cannot used in versions after qt3 (as far i'm aware).
class gnycomponentlist:public qlist<gnycomponent> { protected: virtual int compareitems ( qptrcollection::item item1, qptrcollection::item item2 ) { homecoming (((gnycomponent *)item1)->getid()).compare(((gnycomponent *)item2)->getid());} };
i can't figure out way of doing in qt5.3 might be?
you can utilize std::equal
algorithm on qlist
objects, in:
#include <qlist> #include <qstring> #include <algorithm> // std::equal struct person { qstring firstname; qstring lastname; }; int main() { qlist<person> personsa, personsb; // populate personsa , personsb bool equal = std::equal( personsa.begin(), personsa.end(), personsb.begin(), []( const person &a, const person & b ) { homecoming a.firstname == b.firstname; } ); }
c++ qt compare qlist
Comments
Post a Comment