[Interest] Expose C++ singleton to JavaScript file?
Jason H
jhihn at gmx.com
Thu Jun 24 16:25:21 CEST 2021
I attempted to google this, but I kept getting hits for the wrong thing.
I have a C++ QObject class ("ApplicationDatabase") exposed to QML via
qmlRegisterSingletonInstance("com.company", 1, 0, "ApplicationDatabase", &m_applicationDatabase);
I have a app.js (.pragma library) that is included in many QML components (X.qml) I want the to use the slots/Q_INVOKABLE functions in the app.js:
i.e.
function userRoles(user) {
return ApplicationDatabase.userRoles(user);
}
However when trying to run this, I get:
qrc:/app.js:165: ReferenceError: ApplicationDatabase is not defined
How do I make the .js file aware of the singleton?
More information about the Interest
mailing list