Two QML classes connected to the same C++ class!

  • Hey!

    I have to different QML classes, which I want to connect to the same c++ class. I tried importing the C++ class in both QML classes, but then I get two different instances /objects of the c++ class. I wonder if there is a way to connect both of them to the same object?

  • Qt Champions 2017

    Create C++ object and export to QML using setContextProperty. Use this object in QML. Exporting the classes will export class and not the object.

    @UserData *user = new UserData("","pthinks123");

    //Get the QML Engine
    QQmlEngine *eng = view.engine();
    QQmlContext *context = eng->rootContext();


    UserDB is accessible in QML files. Hope this is what you are asking for.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.