Important: Please read the Qt Code of Conduct -

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

  • I have the following project structure:

    | -
    | - MyAppUi
    | -
    | - MyAppLib
    | -

    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

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

    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