Important: Please read the Qt Code of Conduct -

Composing multiple projects, referencing components

  • Summary: How can I use a QML component from a sub-project in the main project?

    I have a project which stitches together components from two other projects, with each sub-project and the project that stitches them together in sub-directories. For example:

    ├── bar
    │   ├──
    │   ├── bar.qrc
    │   ├── main.qml
    │   ├── main.cpp
    │   └── Bar.qml
    ├── combiner
    │   ├──
    │   ├── combiner.qrc
    │   ├── main.qml
    │   └── main.cpp
    └── foo
        ├── foo.qrc
        ├── main.qml
        ├── main.cpp
        └── Foo.qml

    The Foo and Bar apps have a .pro that loads their respective .cpp, which is mostly a wrapper for the main.qml that instantiates a Window to wrap the Foo.qml or Bar.qml class.

    My file references the sub-projects:

    TEMPLATE = subdirs
    CONFIG += ordered
    SUBDIRS = foo bar combiner
    app.depends = foo bar combiner

    In combiner/main.qml I want to be able to do:

    import QtQuick 2.8
    import QtQuick.Window 2.2
    import ??? // WHAT GOES HERE?
    Window {
        Foo { … }
        Bar { … }

    I've tried import "foo".
    I've tried import "../foo".
    I've tried putting a qmldir file in the Foo directory with the contents module Foo and using import Foo 1.0.
    I clearly don't understand how all the references work, especially with sub-projects.

    How can I make foo/Foo.qml available to combiner/main.qml as a Foo component?

  • Update: I tried adding:


    to combiner/main.cpp before engine.load(), still no success.

    I've also tried adding Foo Foo.qml to foo/qmldir. Still no success.


  • Hello,

    On this page :

    under : Introduction to Application Development with Qt Quick title, there are 3 Links to download
    the tuorial, and the 3rd part of that tutorial will answer you question.


  • I've had a similar problem. The third part of the above linked tutorial is called "Qt Quick Core Principles for Application Development" I looked around that part and a few other parts but could not see a solution. Am I looking in the right place?

  • @JeTSpice Hello, this is not 3rd part, my bad. PART 8 : 8.1 Creating Components and Collecting Modules.
    I hope this is what you are looking for.

Log in to reply