Two QML classes connected to the same C++ class!
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?
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("pthinks.com","pthinks123");
//Get the QML Engine QQmlEngine *eng = view.engine(); QQmlContext *context = eng->rootContext(); context->setContextProperty("UserDB",user);
UserDB is accessible in QML files. Hope this is what you are asking for.