Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QML Module not found | QML_ELEMENT | Working with separate sub-projects



  • I have the following project structure:

    MyApp
    | - MyApp.pro
    | - MyAppUi
    | - MyAppUi.pro
    | - MyAppLib
    | - MyAppLib.pro

    MyAppUi contains qml files, and MyAppLib contains c++ files. These two are separate sub-projects with their own .proj files, and they both live under the MyApp parent dir.

    I previously had c++ files in MyAppUi that I exposed using QML_ELEMENT to qml. The QML_IMPORT_NAME declarations were under the MyAppUi .pro file. The system worked fine and was able to detect the module.

    I have now moved the c++ files to the MyAppLib directory, and the QML_IMPORT_NAME declarations are now under the MyAppLib .pro file. MyAppUi is now no longer picking up the module.

    What do I need to configure to expose the c++ types declared in a different sub project/directory (MyAppLib) to MyAppUi? I just need to detect the module name.

    This is probably a trivial issues but I've been on it for the past two days and haven't had a breakthrough. Please help.


  • Moderators

    @Tee_
    i am not 100% sure if i understand what you are trying to do or because you need the import name in another project.
    but move it to a .pri file and include it in both projects



  • Hello @raven-worx

    My issue was that when I was trying to define the module in the MyAppUi.pro file, the system was not picking up the c++ files with QML_ELEMENT in the MyAppLib project. I specified the import path but it was still not picking them up and registering them.

    So I moved the module declaration to MyAppLib.pro and tried importing it in the qml files in MyAppUi, but the module could not be detected. Maybe what I was trying to do didn't make sense anyway, idk.

    I just reverted to the older way of registering the types with qmlRegisterType.

    Bleh 😓


  • Moderators

    @Tee_
    normally a pro file results in a separate target (executable or library). Even if you "combine" them with a subdirs project.
    So your AppUi project must link against the AppLib