PDA

View Full Version : Passing the object from QML to CPP file?



Mathan
29th July 2016, 16:03
Hi,
I am developing an app.
Query:
How to pass the object from QML to CPP file, what will be object type in QT?

Code:
Login.QML


function metPassObject()
{

var myCar = new Object();
myCar.make = "Ford";
myCar.model = "Mustang"
myCar.year = 1969;

objQtCPPSearchVOne.metPassObject(myCar);

}

.H file:


Q_INVOKABLE void metPassObject (type parameter)- what will be the parameter type?

.CPP file:


void metPassObject(type parameter)
{
//How to access the object?
}


Thanks is Advance.

anda_skoa
29th July 2016, 17:09
My guess would be QJSValue



void metPassObject(const QJSValue &value)
{
QString make = value.property("make");
}


But there could be other ways of achieving your actual goal.

E.g. is this function intended to be called with different objects from different parts of the QML?

Cheers,
_