invoking QObject operators from JS/QML
-
Hi all -
I'm trying to invoke the (in)equality operator of a QObject-derived class from QML, but, according to the debugger, I never hit the operator.
class Equipment : public QObject { Q_OBJECT QML_ELEMENT public: explicit Equipment(QObject *parent = nullptr); virtual bool operator == (const Equipment &rhs) const; virtual bool operator != (const Equipment &rhs) const { return !operator==(rhs); }; // qml ColumnLayout { property Equipment equipmentCopy property Equipment equipmentOriginal: equipmentModel.getEquipment(equipmentCopy.uuid) Button { onClicked: { if (equipmentCopy !== equipmentModel.getEquipment(equipmentCopy.uuid)) { ...Is this not possible, or am I just doing something wrong?
Thanks...
-
@kshegunov said in invoking QObject operators from JS/QML:
@mzimmers said in invoking QObject operators from JS/QML:
Well ... if it ain't invokable (or a slot), I suppose it's hard for the engine to know it should be exposed to QML, right?
I did try using Q_INVOKABLE with no change in behavior. I should have mentioned that.
Although, having an equality operator for a
QObjectis very unusual ...Really? Why is that?
@mzimmers said in invoking QObject operators from JS/QML:
I did try using Q_INVOKABLE with no change in behavior. I should have mentioned that.
I see. Well I'm not sure, to be honest, but you could quickly check if it works with a regular method.
Also you could try/see if the comparison operators are registered with the meta-type system.
... although as I think of it, this doesn't make much sense, asQObjects are not meta-types to begin with ...Really? Why is that?
Because
QObjects are all different (i.e. they are identities)
https://doc.qt.io/qt-6/object.html#identity-vs-value -
Hi all -
I'm trying to invoke the (in)equality operator of a QObject-derived class from QML, but, according to the debugger, I never hit the operator.
class Equipment : public QObject { Q_OBJECT QML_ELEMENT public: explicit Equipment(QObject *parent = nullptr); virtual bool operator == (const Equipment &rhs) const; virtual bool operator != (const Equipment &rhs) const { return !operator==(rhs); }; // qml ColumnLayout { property Equipment equipmentCopy property Equipment equipmentOriginal: equipmentModel.getEquipment(equipmentCopy.uuid) Button { onClicked: { if (equipmentCopy !== equipmentModel.getEquipment(equipmentCopy.uuid)) { ...Is this not possible, or am I just doing something wrong?
Thanks...
@mzimmers said in invoking QObject operators from JS/QML:
Is this not possible, or am I just doing something wrong?
Well ... if it ain't invokable (or a slot), I suppose it's hard for the engine to know it should be exposed to QML, right?
Although, having an equality operator for aQObjectis very unusual ... -
@mzimmers said in invoking QObject operators from JS/QML:
Is this not possible, or am I just doing something wrong?
Well ... if it ain't invokable (or a slot), I suppose it's hard for the engine to know it should be exposed to QML, right?
Although, having an equality operator for aQObjectis very unusual ...@kshegunov said in invoking QObject operators from JS/QML:
@mzimmers said in invoking QObject operators from JS/QML:
Well ... if it ain't invokable (or a slot), I suppose it's hard for the engine to know it should be exposed to QML, right?
I did try using Q_INVOKABLE with no change in behavior. I should have mentioned that.
Although, having an equality operator for a
QObjectis very unusual ...Really? Why is that?
-
@kshegunov said in invoking QObject operators from JS/QML:
@mzimmers said in invoking QObject operators from JS/QML:
Well ... if it ain't invokable (or a slot), I suppose it's hard for the engine to know it should be exposed to QML, right?
I did try using Q_INVOKABLE with no change in behavior. I should have mentioned that.
Although, having an equality operator for a
QObjectis very unusual ...Really? Why is that?
@mzimmers said in invoking QObject operators from JS/QML:
I did try using Q_INVOKABLE with no change in behavior. I should have mentioned that.
I see. Well I'm not sure, to be honest, but you could quickly check if it works with a regular method.
Also you could try/see if the comparison operators are registered with the meta-type system.
... although as I think of it, this doesn't make much sense, asQObjects are not meta-types to begin with ...Really? Why is that?
Because
QObjects are all different (i.e. they are identities)
https://doc.qt.io/qt-6/object.html#identity-vs-value -
M mzimmers has marked this topic as solved on