1. 在cpp中,不能定义引用。
Q_INVOKABLE functionCall(QString & ref);
Q_INVOKABLE使functionCall能在qml中被调用,ref是个引用,会报undefiner的错误。
2. 在qml中,通过CPP返回指针能达到内存共享
//cpp code
struct Car{
int a;
int b;
}
Q_INVOKABLE Car * functionCall(){
return new Car;
}
//qml code
Item{
var car;
Button{
onClicke:{
car = functionCall();//
car.a = 9; //可以修改在CPP中new出来的Car;
}
}
}
3. 在CPP中,可以使用指针访问qml中的组件
//cpp code
class Stu{
int a;
}
//qml code 在其它地方把class Stu注册为qml组件名Student
Student{//使用组件名Student
id:std1;
}
//cpp code
int main(){
set(std1);
}
//cpp code
Q_INVOKABLE set(Student * p){
p->a = 9;//访问qml中的变量
}
4. Qt类型QString,QVariantList,QVariantMap,QStringList,等等,可以直接在qml c++交互使用