Problems with Open-Source Downloads read and

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?

    #include "zh_global_class.h"
    zhGlobalClass g_class; //<--------
    int main(int argc, char *argv[])
    QGuiApplication app(argc, argv);
    QQmlApplicationEngine engine;
    QQmlContext *ctext=engine.rootContext();

    ctext->setContextProperty("zhGlobalClass", &g_class);
    // zhGlobalClass g_class2;
    // ctext->setContextProperty("zhGlobalClass", &g_class2);

    Window {

    id: win_root
    visibility: Window.FullScreen

    zhGlobalClass.setScreenSize( win_root.width, win_root.height )
    target: zhGlobalClass //<--------

  • Qt Champions 2017

    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 QObjects before your QApplication has been created.

Log in to reply