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:
    0_1526583350345_8163dc64-6328-41f9-8382-74bcd4ba852e-image.png

    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

    Thanks



  • 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.