Qt Designer not showing components when using a C++ import in QML



  • Hello all,

    When I use a C++ class in QML passing it to context using qmlRegisterType, any components using the registered import get this warning saying that the defined module is not installed.
    This results in these components not being shown in Qt Designer when we are designing their parents.

    This is my current structure:

    main.qml
    |
    |_ MyComponent.qml

    MyComponent uses a C++ registered import and I can edit it using QtDesigner without a problem (apart from the warning message at the topmost item).

    main.qml Cannot be edited using QtDesigner because MyComponent cannot be loaded (with the same warning, module not installed).

    Is this a known issue? Is it possible to work around it without commenting the lines that use the module and the module import?

    Best regards,

    Theo



  • What I would do is to mockup the C++ types using a pure QML plugin and creating a .qmlproject file for it.

    Here is an example of a project that contains a pure QML plugin and works in the designer:
    https://github.com/qtproject/qt-creator/tree/master/tests/manual/qml/testprojects/plugins

    The full solution is to move your C++ types into a normal plugin and to make this plugin available to the designer.



  • QtCreator is able to read qmlRegisterTypes calls in source code and add these types to the ones he recognize.

    It is working for me, less in certain cases:

    • One case is when the name or namespace is defined dynamically.
    • When register is done in a implementation of a virtual method.

    I am not completely sure i am right... but that is my case

    I dont know how hard would be to add to QtCreator a function like "permissibe QML types detector" to check in the code for qmlRegisterType<> and match them with the types used in QML code. And inference them (using class name, class name registration, and namespace used)

    it works for me quite well, as it search inside macros, but i am still missing a solution for the second case...



  • While the code model does scan for qmlRegisterType the Qt Quick Designer has to be able to instantiate the real C++ class.
    To be able to do this the C++ class/type has to be moved into a real QML plugin the Qt Quick Designer (qml2puppet) can load.



  • @Thomas-Hartmann

    The problem i see is that QtCreator model is too restrictive...

    I just found another problem

    I have a plugin, CustomPluginBase
    And i develop an app that uses this plugin, linking statically so i can extend some types in cpp, and i register new types under namespace "CustomPluginBase.ExtendedTypes"

    Well, QtCreator shows "QML module not found" and as types doesn't exist, even if application works perfectly if i run it. (they get registered)

    I imagine that QtCreator overwrite existing qmlRegisterType in code, with no existing plugin, as base plugin exist.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.