Connecting the global class to QML will make my app crash on my android
I want to use my global class in cpp and qml.
But it will make my app crash on android device.
I find it work fine when I create the instance in main function like the
comment in below code . But I want to define global scope variable.
What should I do when I want to connect the global class to QML?
zhGlobalClass g_class; //<--------
int main(int argc, char *argv)
QGuiApplication app(argc, argv);
// zhGlobalClass g_class2;
// ctext->setContextProperty("zhGlobalClass", &g_class2);
zhGlobalClass.setScreenSize( win_root.width, win_root.height )
target: zhGlobalClass //<--------
I'm not sure about your use case. I had similar use case. Instead of making the global object , I made it as global pointer and created object inside the main function.
Issue is coming because global object is created in different thread context than the QML engine thread context. This is causing the issue on Android. This works on desktop version.
You must not create
QApplicationhas been created.