Reputation: 7448
I want to pass the QML item reference to C++. It works using the id explicitly:
Item {
id: qmlitem
x: CppObj.getValue(qmlitem)
}
// c++
int getValue(QObject * qmlItem) {
return 0;
}
if I pass this:
Item {
x: CppObj.getValue(this)
}
QObject * qmlItem is 0x0.
If I replace
int getValue(QObject * qmlItem)
by
int getValue(void * qmlItem)
qmlItem is not 0x0 - it has a value but of which type? Is it possible to obtain the QObject* from it?
Upvotes: 2
Views: 82
Reputation: 3851
In QML, the value of this
is currently undefined. Passing it to C++ will not yield any meaningful result. Whatever its content may be, it is not a reference to the current QML item. So just stick to your first solution and pass an ID.
Upvotes: 3