0

I have installed the latest Qt 5.5.0, but there seems to be only QtQuick.Controls 1.0 and 1.1. I want to use TreeView, which is contained in the 1.4 version.

BaCaRoZzo
  • 7,502
  • 6
  • 51
  • 82
Zen
  • 5,065
  • 8
  • 29
  • 49
  • Thanks. Found on 3 different directories `~/Qt5.5.0/5.5/Src/qtquickcontrols/src/controls/TreeView.qml--- ~/Qt5.5.0/5.5/gcc_64/qml/QtQuick/Controls/TreeView.qml--- ~/Qt5.5.0/Tools/QtCreator/bin/qml/QtQuick/Controls/TreeView.qml` Which one should I add to the path? @VictorPolevoy – Zen Aug 25 '15 at 13:12
  • Wait... did you actually try to run an example that uses the 1.4 version of the controls? – Mitch Aug 25 '15 at 15:08
  • Dude, there are so many examples, how do you know which one uses the 1.4 version. Whatever, I found one. Though qt creator keeps warning `TreeView` component is not found, it works. Thanks @Mitch – Zen Aug 26 '15 at 05:19

3 Answers3

2

You should already have it. Try to find the TreeView.qml by using locate TreeView.qml. Also, QtCreator or your IDE should have proper QML_IMPORT_PATH which is taken from environment. For example, my QtCreator does not have set proper paths so I use it with shell script which sets the path and runs /usr/bin/qtcreator after - this makes QtCreator to see new QML modules. I don't know is this a bug or just a ubuntu-package problem, but it worked for me only when I set the QML_IMPORT_PATH manually.

You say you have these paths:

~/Qt5.5.0/5.5/Src/qtquickcontrols/src/controls/TreeView.qml

~/Qt5.5.0/5.5/gcc_64/qml/QtQuick/Controls/TreeView.qml

~/Qt5.5.0/Tools/QtCreator/bin/qml/QtQuick/Controls/TreeView.qml

Looks like you installed it by downloading official installer from Qt's site. So, the first path is a sources path. Don't use it ever, it is only needed to be installed into correct directory after compiling Qt from sources and performing make install.

The third one is integrated with your QtCreator installation, but it seems it does not work for you.

I'd say, your choice is to use second path (~/Qt5.5.0/5.5/gcc_64/qml/QtQuick/Controls/TreeView.qml). It is usually installed automatically to /usr/lib/x86_64-linux-gnu/qt5/ on amd64 architecture and to /usr/lib/i386-linux-gnu/ for i386 architecture.

So, create a script in /usr/bin/, call it dev-qtcr for example and put inside it:

#!/bin/bash

export QML_IMPORT_PATH=/home/user/Qt5.5.0/5.5/gcc_64/qml
qtcreator

Be sure to change /home/user to your home directory.

VP.
  • 15,509
  • 17
  • 91
  • 161
  • So, I add `QML_IMPORT_PATH = /home/zen/Qt5.5.0/5.5/gcc_64/qml` to my .pro file. But that does't work. Where should I set the path variable? – Zen Aug 25 '15 at 14:20
  • @Zen This is also an environment variable. Set it to this path and run qtcreator after this in the same tty. I was not able to work with new qml components by just modifying `.pro` file too - that's why I made a shell script. I may give you details few hours later. – VP. Aug 25 '15 at 14:22
  • Maybe there's something wrong with qt creator. Setting the environment variable doesn't make a difference. I find that I can import the 1.4 version, though qt creator keeps warning `TreeView` component is not found, it works. – Zen Aug 26 '15 at 05:23
  • @Zen I'll check this out this evening. Maybe it works the same way for me, I am not sure. I'll notify you asap. – VP. Aug 26 '15 at 06:19
  • @Zen god, had no time for this. Maybe **this** evening. Also, what if you use a qtcreator from `~/Qt5.5.0/Tools/QtCreator/bin/` directory? Does it work okay in this case? – VP. Aug 27 '15 at 06:25
1

Did you tried to export QML2_IMPORT_PATH rather than QML_IMPORT_PATH ?

See Import Statements | Qt QML

Thom Armax
  • 147
  • 1
  • 11
  • Qt creator still warns that `TreeView` is unknow. – Zen Aug 26 '15 at 16:27
  • You can try to define the QML2_IMPORT_PATH in the project configuration : Project -> Build and Run -> -> Run ->Run Environment -> Details -> Add Add *QML2_IMPORT_PATH* and set the value to */home/zen/Qt5.5.0/5.5/gcc_64/qml* – Thom Armax Aug 27 '15 at 07:46
  • Have you built and installed Qt5.5 ? If your setup is Ok, every thing should work out out the box. Once Qt5.5 is installed, you have in QtCreator to add the freshly installed version and create a new kit. The configure your project to use the kit you have created for Qt5.5. – Thom Armax Aug 27 '15 at 11:19
  • Thanks, I will try it later. BTW, could you please tell whether this leads to memory leak? I have a listview whose width is bound to this function`function calcWidth(){ var w = 0; for(var i in list.contentItem.children) { var child = list.contentItem.children[i]; w+=child.width; } return w } ` – Zen Aug 27 '15 at 13:17
  • Well, I don't think that will lead to memory leak. – Thom Armax Aug 27 '15 at 15:06
0

An other solution, which is quite ugly, is to edit the qmldir file from gcc/qml/QtQuick/Controls and add the following line:

TreeView 1.4 TreeView.qml

As a result for me :

module QtQuick.Controls
plugin qtquickcontrolsplugin
classname QtQuickControlsPlugin
typeinfo plugins.qmltypes
designersupported
depends QtQuick.Window 2.2 
TreeView 1.4 TreeView.qml

You can do so for each QML file which is in the QtQuick/Controls directory.

In this way, TreeView and all other QML types you will add to this file will be recognized by QtCreator.

See http://doc.qt.io/qt-5/qtqml-modules-qmldir.html

Thom Armax
  • 147
  • 1
  • 11