Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

Fastest way to compare QVariant with UserType

$
0
0
I’m looking for a very fast way to compare two QVariants that wrap the same user type. What do you think about the following approaches: bool operator==() const(const QVariant &rhs) { if(myData.userType() == qMetaTypeId<MyUserType>()) { bool method1 = *static_cast<MyUserType*>(myData.constData())  == *static_cast<const MyUserType*>(rhs.myData.constData());   bool method2 = myData.value<MyUserType>() == rhs.myData.value<MyUserType>(); } return something } I would think that the first approach is faster, because no deep copy or ctor call is necessary. It is more risky because of the static_cast and kind of a hack though. I took a look into the Qt implementation of the second method, but as far as I could see, at least once the copy ctor of MyUserType is called.

Viewing all articles
Browse latest Browse all 18427

Trending Articles