PDA

View Full Version : implement object comparison in C++



gsv-chris
19th February 2015, 14:01
Hello,

I am trying to determine whether it is possible to implement QObject types such that they provide "logical equality". By this I mean, that 2 objects that are physically different can be determined to be representing the same application value (in my case, the QObjects are wrapping non-Q application objects). I would like to write the comparison as

Component.onCompleted: {checked = (selectedProject == project)}
my investigations so far have shown that this is impossible because comparison operators in Javascript cannot be overloaded. Since I cannot ensure the uniqueness of the QObject wrappers, I will have to go with a "sameAs" Q_INVOKABLE methd, and change the QML/Javascript code to

Component.onCompleted: {checked = selectedProject.sameAs(project)}

any commmments?
thanks,
chris