简体   繁体   中英

How to import the QML-Book examples into QT Creator 3.4.0?

How can I import these code examples into QT Creator 3.4.0 ? I tried the available import options but they don't work.

I tried to create an empty QML project and add the rectangle.qml file to it. When I tried to run it, nothing showed up.

The book examples contain files .qmlproject - which seems to be a project descriptor. I wonder if it is somehow possible to import these .qmlproject files into QT Creator, click and run the examples.

I think this link might help in finding the solution : https://forum.qt.io/topic/27525/what-is-qmlproject-file/3 .

在此处输入图片说明

Usually I'd say that you should go to File > Open File or Project... and select the .qmlproject and you're done, but support for this type of project file was disabled by default . If you try to do this now (I believe the change is in Creator 3.4), you'll just get an error message about Creator not supporting the mime type of the file, or something. Unfortunately, this is not a very useful error message for a beginner, and it won't tell you how to fix the problem.

If you want to use .qmlproject files in newer versions of Creator, you have to navigate to Help > About Plugins... and enable the QmlProjectManager plugin (it's under the Qt Quick section) by checking the box.

So this is how you should normally open project files in Qt Creator. As for the window not showing up, that's also commonly encountered and can be fixed by making the root item in your scene a Window :

Unlike QQuickView, QQmlApplicationEngine does not automatically create a root window. If you are using visual items from Qt Quick, you will need to place them inside of a Window.

Qt Creator's new project wizard handles this for you when you create a new Qt Quick project, as you saw when you got the "Hello World" window to open in your video. It was when you loaded concepts/rectangle.qml which had a Rectangle as its root item, that it stopped showing up. That QML file was likely used in a project where a QQuickView was displaying it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM