Alexey saved the day: https://doc.qt.io/qt-5/qtqml-javascript-imports.html#importing-a-qml-module-from-a-javascript-resource
Thanks! > Sent: Thursday, June 24, 2021 at 10:25 AM > From: "Jason H" <jh...@gmx.com> > To: "interestqt-project.org" <interest@qt-project.org> > Subject: [Interest] Expose C++ singleton to JavaScript file? > > 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? > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > https://lists.qt-project.org/listinfo/interest > _______________________________________________ Interest mailing list Interest@qt-project.org https://lists.qt-project.org/listinfo/interest