Unsolved 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:
. ├── app.pro ├── bar │ ├── bar.pro │ ├── bar.qrc │ ├── main.qml │ ├── main.cpp │ └── Bar.qml ├── combiner │ ├── combiner.pro │ ├── combiner.qrc │ ├── main.qml │ └── main.cpp └── foo ├── foo.pro ├── 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 themain.qml
that instantiates a Window to wrap theFoo.qml
orBar.qml
class.My
app.pro
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 triedimport "../foo"
.
I've tried putting aqmldir
file in theFoo
directory with the contentsmodule Foo
and usingimport 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 tocombiner/main.qml
as aFoo
component? -
Update: I tried adding:
engine.addImportPath("foo"); engine.addImportPath("../foo");
to combiner/main.cpp before
engine.load()
, still no success.I've also tried adding
Foo Foo.qml
tofoo/qmldir
. Still no success.Ping?
-
Hello,
On this page : http://wiki.qt.io/Developer_Guides
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.LA
-
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.
LA