[Qt-qml] Adding QML components dirs

927 views
Skip to first unread message

Bo Thorsen

unread,
Mar 8, 2012, 5:04:12 PM3/8/12
to qt-...@qt.nokia.com
Hi people,

I'm working on a project, where I have QML files in several directories.
This isn't a problem at runtime, because they're all copied to the same
qml dir.

But in QtC, I get the red error line under the components from other
dirs, and no completion.

I seem to remember that there is a way I can add dirs to the QML parser
to complete from, but I can't find it anymore. Anyone here have a good idea?

The setup is that I have a library that's shared between different
projects, and some of the files in this library are QML files, some are
C++. The C++ code isn't a problem, of course, but the QML files are
annoying.

Using svn externals directly on the file would put them in the same qml
dir as the files specific to the other projects, but that's a
maintenance nightmare.

Bo Thorsen,
Fionia Software.

--

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk
_______________________________________________
Qt-qml mailing list
Qt-...@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Harri Pasanen

unread,
Mar 9, 2012, 4:26:54 AM3/9/12
to qt-...@qt.nokia.com
I wonder if creating a qmldir file would help, even if C++ is not used?

http://doc.qt.nokia.com/qtcreator-2.4/creator-qml-modules-with-plugins.html

/Harri

On 03/08/2012 11:04 PM, Bo Thorsen wrote:
> Hi people,
>
> I'm working on a project, where I have QML files in several directories.
> This isn't a problem at runtime, because they're all copied to the same
> qml dir.
>
> But in QtC, I get the red error line under the components from other
> dirs, and no completion.
>
> I seem to remember that there is a way I can add dirs to the QML parser
> to complete from, but I can't find it anymore. Anyone here have a good idea?
>
> The setup is that I have a library that's shared between different
> projects, and some of the files in this library are QML files, some are
> C++. The C++ code isn't a problem, of course, but the QML files are
> annoying.
>
> Using svn externals directly on the file would put them in the same qml
> dir as the files specific to the other projects, but that's a
> maintenance nightmare.
>
> Bo Thorsen,
> Fionia Software.
>

_______________________________________________

christia...@nokia.com

unread,
Mar 10, 2012, 4:18:20 AM3/10/12
to b...@fioniasoftware.dk, qt-...@qt.nokia.com
If it is a qmake project, set QML_IMPORT_PATH in the .pro file to add paths to Creator's code model.

Cheers,
Christian

________________________________________
From: qt-qml-bounces+christian.d.kamm=noki...@qt.nokia.com [qt-qml-bounces+christian.d.kamm=noki...@qt.nokia.com] on behalf of ext Bo Thorsen [b...@fioniasoftware.dk]
Sent: Thursday, March 08, 2012 11:04 PM
To: qt-...@qt.nokia.com
Subject: [Qt-qml] Adding QML components dirs

Bo Thorsen

unread,
Mar 12, 2012, 2:53:49 AM3/12/12
to christia...@nokia.com, qt-...@qt.nokia.com
Hi Christian,

QML_IMPORT_PATH was exactly the variable I was looking for, thanks. But
unfortunately it doesn't work :(

I have a directory structure that looks like this:

project/
qml/
Most QML files here
mylib/
qml/
More QML files

The mylib.pri installs the qml files to the same qml directory as the
main qml files, so at runtime this is fine.

I have added "QML_IMPORT_PATH = mylib/qml" to the pro file. This doesn't
make any difference to the QtC code model. I have tried stuff like
adding $$PWD and other attempts. No difference. The components are not
recognised.

In the meantime, I have worked around it by adding a line saying
'import "../mylib/qml"' and installing the library components to a
separate directory that has the same path in the runtime dir as in the
source dir. It does work, but it means I restrict the way the source
tree is set up, and I really don't like that.

If anyone know why QML_IMPORT_PATH doesn't work for me, please tell.
Otherwise, I'll enter a bug report.

Cheers,

Bo.

Sven Anderson

unread,
Mar 12, 2012, 7:16:19 AM3/12/12
to qt-...@qt.nokia.com
Hi Bo,

On 12.03.2012 07:53, Bo Thorsen wrote:
> QML_IMPORT_PATH was exactly the variable I was looking for, thanks. But
> unfortunately it doesn't work :(
>
> I have a directory structure that looks like this:
>
> project/
> qml/
> Most QML files here
> mylib/
> qml/
> More QML files
>
> The mylib.pri installs the qml files to the same qml directory as the
> main qml files, so at runtime this is fine.
>
> I have added "QML_IMPORT_PATH = mylib/qml" to the pro file. This doesn't
> make any difference to the QtC code model. I have tried stuff like
> adding $$PWD and other attempts. No difference. The components are not
> recognised.

What is the name of your mylib module? If I understand it correctly it
is like that: if your module name is "dk.fioniasoftware.mylib" it would
look for mylib/qml/dk/fionasoftware/mylib/. So I would suggest to create
a directory-structure somewhere like somewhere/dk/fionasoftware/mylib,
where mylib is a symbolic link to mylib/qml. Then you set
QML_IMPORT_PATH = somwhere/dk/fionasoftware/mylib
and it should find the QML stuff in mylib/qml if you import
dk.fioniasoftware.mylib. But I didn't try it, just a guess.


Good luck,

Sven

christia...@nokia.com

unread,
Mar 12, 2012, 5:25:36 PM3/12/12
to b...@fioniasoftware.dk, qt-...@qt.nokia.com
> QML_IMPORT_PATH was exactly the variable I was looking for, thanks. But
> unfortunately it doesn't work :(

...

> The mylib.pri installs the qml files to the same qml directory as the
> main qml files, so at runtime this is fine.

Ah, I'm sorry, that's not something QML_IMPORT_PATH can help with. It just adds to the QML module search path so qmldir files below the listed directories will be found. E.g. if you have

foo/my/module/qmldir

and set it to foo/ you could "import my.module". It won't help in your situation. The best solution is using an import like you did in your workaround.

Cheers,
Christian,

Bo Thorsen

unread,
Mar 13, 2012, 11:12:50 AM3/13/12
to christia...@nokia.com, qt-...@qt.nokia.com
Den 12-03-2012 22:25, christia...@nokia.com skrev:
>> QML_IMPORT_PATH was exactly the variable I was looking for, thanks. But
>> unfortunately it doesn't work :(
>
> ...
>
>> The mylib.pri installs the qml files to the same qml directory as the
>> main qml files, so at runtime this is fine.
>
> Ah, I'm sorry, that's not something QML_IMPORT_PATH can help with. It just adds to the QML module search path so qmldir files below the listed directories will be found. E.g. if you have
>
> foo/my/module/qmldir
>
> and set it to foo/ you could "import my.module". It won't help in your situation. The best solution is using an import like you did in your workaround.

Ok, thanks for confirming this. I wasn't able to find the answer for
sure in the documentation, although I did suspect it to be the case.

Bo Thorsen,
Fionia Software.

--

Expert Qt and C++ developer for hire
Contact me if you need expert Qt help
http://www.fioniasoftware.dk

Reply all
Reply to author
Forward
0 new messages