Unsolved Qt Creator doesn't see qml types in locally intalled qml molule
-
I've created my project which consists of main.cpp, main.qml and module in some other local directory which I want to import.
My application builds and works well.
But Qt Creator doesn't see types from module and accentuatesimport MyModule 1.0
in main.qml file with red line.
How is it possible to make my module visible to Qt Creator?
-
Hi! Let's say your module is named "MyControls". And let's assume your application get's installed to
install-root/bin/myapp.exe
. You must then put your module in a sub-directory with the exact same name, here:install-root/bin/MyControls/
. And you need the following files to be installed into that directory:MyControls.dll // compiled shared object part of the module SomeItem.qml AnotherItem.qml qmldir // special file plugins.qmltypes // special file
The
qmldir
file has to look like this:module MyControls plugin MyControls SomeItem 1.0 SomeItem.qml AnotherItem 1.0 AnotherItem.qml
And the file
plugins.qmltypes
must be generated withqmlplugindump
(see Generating qmltypes Files).And finally you need to tell Qt Creator where to find your module, by adding the directory to the QML module import path variable. With Qbs you can skip that last part and just add the following to your .qbs file:
property string qmlImportPaths: "/blah/foo/bar/install-root/bin"
And, yes, it's complicated ;-)
-
Great thank for your answer!
Could you please explain what is plugin MyControls and MyControls.dll? Is it C++ plugin?
And how to say Qt Creator about path where it is necessary to fing module? I included this path into INCLUDEPATH variable. But it didn't work.
My application builds and works well. But when I edit code Qt Creator doesn't recognize types from module. Application runs well despite of it. -
Could you please explain what is plugin MyControls and MyControls.dll? Is it C++ plugin?
Yes, exactly. You can find in-depth info in Creating C++ Plugins for QML, and there is also an example: QML Plugin Example.
And how to say Qt Creator about path (...) ?
You need to add the path that contains your module-directory to the
QML2_IMPORT_PATH
environment variable. The easiest place to do that is in project settings > run environment:QML2_IMPORT_PATH = /blah/foo/bar/install-root/
-
Unfortunetely It doen't work.
This is my project settings
This is my main.qml
This is project directory:
This is MyModule directory:
And this is qmldir file:
What is wrong?