1

I created the "BottomBar.qml" component in the UI folder and when I import it into the main.qml file it is giving me an error. could you help please

BottomBar.qml Component BottomBar

main.qml main.qml

Error message Error

I'm following a tutorial and doing exactly the same as the video but it doesn't work. I tried deleting the entire project and creating it again but to no avail.

10
  • Can you share the link to the tutorial? Commented Mar 6, 2023 at 11:04
  • youtube.com/watch?v=Tq-E6lqO6tM&t=515s Minute 7:00 Commented Mar 6, 2023 at 11:12
  • He uses a qrc file to list all the available QML files, you can see it on the left in his project tree. I guess he uses an older version of QtCreator which has a slightly different project template that automatically creates the qrc file. doc.qt.io/qt-5/resources.html Commented Mar 6, 2023 at 11:41
  • During the video it does not show the contents of this file. Would you have any documentation on how to create it in version 6.4 of QT? I tried looking in the documentation but I couldn't find how to create it. Commented Mar 6, 2023 at 12:11
  • 1
    Welcome to SO. Rather than showing code and error messages as images, please copy and paste the text into your post. Take the tour to learn more about how to write good questions. Commented Mar 6, 2023 at 13:37

1 Answer 1

0

Add your QML component to Qt resource file and then import the QML component from resource file.

Have a look at The Qt Resource System to know how to create and use a resource files.

Basically you need to do the following:

Right Click Project Name in project explorer --> Add New --> Qt --> Qt Resource File, to create a new resource file.

enter image description here

In the main.qml import the resource file as follows:

import QtQuick
import QtQuick.Window 2.12
import "qrc:/qml/ui/BottomBar"

Window {
    width: 1280 * .5
    height: 720 * .5
    visible: true
    title: qsTr("Tesla Infotainment")

    BottomBar {
        id: bottomBar
    }
}

Then run the application to get the desired result:

enter image description here

Hope it helps you.

Sign up to request clarification or add additional context in comments.

1 Comment

I solved it by creating a new file and putting "Minimun required QT version" as 5.12. Doing this it automatically created qml.qrc and linked main.qml along with the others. But manually adding already with the minimum version 6.4 also worked later. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.