QMLBook Tutorial - Problem building some of their example projects, maybe not setting up projects correctly in Qt Creator
-
I am reading the tutorial at https://qmlbook.github.io and am running into an issue building some of their examples.
I am using QT Creator version 4.8.0, which is "based on Qt 5.12.0". Development platform is Windows 10 64-bit. I have downloaded all of the tutorial examples and arranged them like this (list severely edited and truncated):
+---\Users\cjc\Qt +---examples +---ch04-qmlstart \---src +---concepts | concepts.qmlproject | concepts.qmlproject.user | RectangleExample.qml | tst_rectangleexample.qml +---elements elements.qmlproject elements.qmlproject.user ReusableComponentExample.qml
I then open QT Creator and say File->Open File or Project, then navigate to the desired "qmlproject" file (in this case concepts.qmlproject), then double click. The project opens and shows me a list of all of the qml files in the project. I double-click on one (RectangeExample.qml) and am able to build and run using the "run" arrow in the lower left corner of QT Creator. So far so good.
Now I say File->Close All Projects and Editors then File->Open File or Project, navigate to elements.qmlproject, and double click. As before, I get a list of available source files including ReusableComponentExample.qml. I double click on that to open it in the editor. This time, when I try to Run it, I get a pop-up "Open QML File" window wanting me to open the source file again. I double-click on ReusableComponentsExample.qml (again), and now am able to build and run.
My question is, why am I getting that second prompt to open ReusableComponentsExample.qml when it's already open? I'm thinking there is some linkage somewhere within QT Creator that is broken or missing.
This happens whenever I try to open and build any of the sample projects in Chapter 4; only the "concepts" one works as expected. The others are "elements" (shown in the list above), "anchors", "input", "positioners", and "transformation", each one intended to demonstrate another basic aspect of Qt.
There are two things about the ".qmlproject" files...
-
At the top of each is "File generated by Qt Creator, version 2.4.1" . Does it matter that the Qt Creator version is different?
-
Here is concepts.qmlproject (the one that works correctly):
import QmlProject 1.1 Project { /* Include .qml, .js, and image files from current directory and subdirectories */ QmlFiles { directory: "." } JavaScriptFiles { directory: "." } ImageFiles { directory: "." } /* List of plugin directories passed to QML runtime */ // importPaths: [ "../exampleplugin" ] }
The elements.qmlproject file, the one that forces the second load of the .qml file, is similar but it includes a "mainfile" line:
Project { mainFile: "elements.qml" /* Include .qml, .js, and image files from current directory and subdirectories */ QmlFiles { directory: "." } // ... etc.
I will be happy to make a zipfile out of my tutorial examples file tree and send it to anyone who wants it, or upload it somewhere (does this forum support file uploads?), if that will help diagnose this problem. The zipfile will be about 11 MB in size.
This isn't a big critical holdup and I can go ahead and do the second load, but I'm clearly doing something wrong and would like to know what that might be so I can continue to learn Qt from a valid foundation.
Thanks...
-
-
Good morning, @Yunus
I tried that, but in QT Creator under "Build", the Clean All is greyed out along with everything else except Run, Run Without Deployment, and Open Build and Run Kit Selector.
I did find a workaround, if not a fix... in the qmlproject file if I comment out the "mainfile" line, the issue goes away. So, now I'm trying to figure out exactly what the "mainfile" line does and why it seems to work better without that line (and if so, why did the tutorial authors put that line in there?... there must have been a reason).
-
Hi
looking at your post i noticed that the project that worked has import QmlProject 1.1 and no mainfile. The other one only has the mainfile. You said in your post that the eamples produced using Qtcreator version 2.4.1, but you using version 4.8.0.
I'm wondering if the older version needed the mainfile ,but not the import, but the latest version needs the import and not the mainfile.
Im working through these examples as well, so as an experiment I'll try modifying one of those that acts up so it uses the iport and not the mainfile and report back:)
Update: I tried running elements project as is and did not get your 'glitch'. Looking at the elements.qmlproject file it has the import QmlProject 1.1 line, but NOT the mainfile line. This was only imported from the git assets page today.
As a side issue in concepts, don't try running the tst.* files they will give an error. Digging round reveals these cannot be run using qmlscene , but you need to use the qmltestrunner utility. (not looked into that yet)
-
@robp said :
Update: I tried running elements project as is and did not get your 'glitch'. Looking at the
elements.qmlproject file it has the import QmlProject 1.1 line, but NOT the mainfile line.
This was only imported from the git assets page today.Good afternoon, @robp .
I only just downloaded the file tree from the assets page a few days ago, and my version of elements.qmlproject has the mainfile line. If I comment out that mainfile line, the 'glitch' goes away.
I'll see if there has been an update posted to the assets page in the last few days. Maybe I'm getting my example files from the wrong place.
I'm wondering if I can get the administrators of this QT Forum to add a sub-forum for the QMLBook Tutorial. That seems to be a fairly popular (and so far comprehensive and helpful) tutorial but they don't have an interactive forum like this one, all they have is a bug tracker and a blog that's not subdivided into topics. I will ask.