As I know,QML object will be convert to QVariantMap when transferred to C++ as method parameter, but this is transferred by value and new QVariantMap is created. The performance is not good enough for me.
What if I want to transfer an object by reference to c++ that the object is created by C++ registered type.
As example:
//MyClass is C++ defined QObject-derived class and register to QML
qmlRegisterType<MyClass>("com.mycompany.myclass", 1, 0, "MyClass");
In QML:
var cObj = Qt.createQmlObject('import QtQuick 2.2; import com.mycompany.myclass 1.0;MyClass{}', mwindow, "dynamicMyImageDataCreate");
//cppObj is a C++ object exposed to QML.
cppObj.foo(cObj);
In foo(),I want to convert cObj to as local object. foo may some like this:
void foo(QObject* cObj){
MyClass* mc = (MyClass*)cObj;
cObj -> x;
}
Does Qt support this or is there way I can do this? Does Qt have mechanism to do such thing?
Thanks for replying.
↧