⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

C++ Singleton import inside Qt Creator's QML Designer

  • Hello, I have a C++ singleton registered for qml using such code:

    engine.setObjectOwnership( wrapper, QQmlEngine::CppOwnership );
    qmlRegisterSingletonType<QMLWrapper>( "QMLWrapper", 1, 0, "QMLWrapper", getWrapper );

    In QML I import it using plain import and use as is stated below:

    import QMLWrapper 1.0
    QMLWrapper.onLoginButtonClicked("login", "pass")

    But when I try to enter Form Editor inside Qt Creator, I get error:

    So, is there any way to keep Form Editor working without commenting import statement?

    I use Visual Studio + Qt Plugin to build an application, Qt Creator is used only for editing QMLs


  • I know this answer is a bit late, but one solution that comes to my mind is to separate UI from logic. Create one file (e.g. a ui.qml file) for your UI and use it in another qml file.