Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Importing Multiple QML Files into main.qml
QtWS25 Last Chance

Importing Multiple QML Files into main.qml

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlqt6.4.1multi-screen
7 Posts 3 Posters 1.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jweb1
    wrote on 8 Feb 2024, 19:55 last edited by jweb1 2 Aug 2024, 19:56
    #1

    Hi all,

    I'm new to QML and Qt, but eager to learn. I'm wanting to use several qml files to reduce the size of my main.qml, however, am having trouble doing so.

    I'm using a stack view to navigate between screens (in the example below I have a QML file called DiagnosticsScreens.qml at the same file path as my main.qml file).

    StackView {
            id: stackView
            width: 608
            height: 414
            x: 96
            y: 66
            initialitem: diagnostics_screen
    
            Component { id: diagnostics_screen
                DiagnosticsScreen {}
            }
            
        }
    

    When I try to run I get:
    QQmlApplicationEngine failed to load component
    qrc:/<folder_name>/main.qml:577:13: DiagnosticsScreen is not a type

    Any suggestions are greatly appreciated!!!

    S O J 3 Replies Last reply 8 Feb 2024, 22:05
    0
    • J jweb1
      8 Feb 2024, 19:55

      Hi all,

      I'm new to QML and Qt, but eager to learn. I'm wanting to use several qml files to reduce the size of my main.qml, however, am having trouble doing so.

      I'm using a stack view to navigate between screens (in the example below I have a QML file called DiagnosticsScreens.qml at the same file path as my main.qml file).

      StackView {
              id: stackView
              width: 608
              height: 414
              x: 96
              y: 66
              initialitem: diagnostics_screen
      
              Component { id: diagnostics_screen
                  DiagnosticsScreen {}
              }
              
          }
      

      When I try to run I get:
      QQmlApplicationEngine failed to load component
      qrc:/<folder_name>/main.qml:577:13: DiagnosticsScreen is not a type

      Any suggestions are greatly appreciated!!!

      J Offline
      J Offline
      jweb1
      wrote on 20 Feb 2024, 22:14 last edited by
      #7

      @jweb1 Resolved!

      Note: it was a resources folder problem. Thanks all

      1 Reply Last reply
      0
      • J jweb1
        8 Feb 2024, 19:55

        Hi all,

        I'm new to QML and Qt, but eager to learn. I'm wanting to use several qml files to reduce the size of my main.qml, however, am having trouble doing so.

        I'm using a stack view to navigate between screens (in the example below I have a QML file called DiagnosticsScreens.qml at the same file path as my main.qml file).

        StackView {
                id: stackView
                width: 608
                height: 414
                x: 96
                y: 66
                initialitem: diagnostics_screen
        
                Component { id: diagnostics_screen
                    DiagnosticsScreen {}
                }
                
            }
        

        When I try to run I get:
        QQmlApplicationEngine failed to load component
        qrc:/<folder_name>/main.qml:577:13: DiagnosticsScreen is not a type

        Any suggestions are greatly appreciated!!!

        S Offline
        S Offline
        Sebastiano
        wrote on 8 Feb 2024, 22:05 last edited by
        #2

        @jweb1 said in Importing Multiple QML Files into main.qml:

        DiagnosticsScreen

        What are you using as a project manager?

        Cmake or qmake, either way are you sure you added DiagnosticsScreen.qml to the project?

        And last thing initialItem or initialitem?

        J 1 Reply Last reply 9 Feb 2024, 01:17
        0
        • S Sebastiano
          8 Feb 2024, 22:05

          @jweb1 said in Importing Multiple QML Files into main.qml:

          DiagnosticsScreen

          What are you using as a project manager?

          Cmake or qmake, either way are you sure you added DiagnosticsScreen.qml to the project?

          And last thing initialItem or initialitem?

          J Offline
          J Offline
          jweb1
          wrote on 9 Feb 2024, 01:17 last edited by jweb1 2 Sept 2024, 01:18
          #3

          @Sebastiano
          qtCreator 9.0.1
          I have the DiagnosticsScreen.qml in the same folder as main.qml
          initialItem small typo

          S 1 Reply Last reply 9 Feb 2024, 08:35
          0
          • J jweb1
            8 Feb 2024, 19:55

            Hi all,

            I'm new to QML and Qt, but eager to learn. I'm wanting to use several qml files to reduce the size of my main.qml, however, am having trouble doing so.

            I'm using a stack view to navigate between screens (in the example below I have a QML file called DiagnosticsScreens.qml at the same file path as my main.qml file).

            StackView {
                    id: stackView
                    width: 608
                    height: 414
                    x: 96
                    y: 66
                    initialitem: diagnostics_screen
            
                    Component { id: diagnostics_screen
                        DiagnosticsScreen {}
                    }
                    
                }
            

            When I try to run I get:
            QQmlApplicationEngine failed to load component
            qrc:/<folder_name>/main.qml:577:13: DiagnosticsScreen is not a type

            Any suggestions are greatly appreciated!!!

            O Offline
            O Offline
            oniongarlic
            wrote on 9 Feb 2024, 07:18 last edited by
            #4

            @jweb1 said in Importing Multiple QML Files into main.qml:

            QML file called DiagnosticsScreens.qml at the same file path as my main.qml file).

                        DiagnosticsScreen {}
            

            You say DiagnosticsScreens.qml but are using DiagnosticsScreen.

            1 Reply Last reply
            0
            • J jweb1
              9 Feb 2024, 01:17

              @Sebastiano
              qtCreator 9.0.1
              I have the DiagnosticsScreen.qml in the same folder as main.qml
              initialItem small typo

              S Offline
              S Offline
              Sebastiano
              wrote on 9 Feb 2024, 08:35 last edited by
              #5

              @jweb1
              excuse me I mean are you using qmake or cmake, check if DiagnosticsScreens is defined there.

              also check what is said by @oniongarlic

              J 1 Reply Last reply 10 Feb 2024, 16:27
              0
              • S Sebastiano
                9 Feb 2024, 08:35

                @jweb1
                excuse me I mean are you using qmake or cmake, check if DiagnosticsScreens is defined there.

                also check what is said by @oniongarlic

                J Offline
                J Offline
                jweb1
                wrote on 10 Feb 2024, 16:27 last edited by
                #6

                @Sebastiano
                My bad, I am using qmake.

                I've created a smaller project to make it easier to share. I feel like it shouldn't be hard but it's really grinding my gears lol.

                //main.qml

                import QtQuick 2.15
                import QtQuick.Window 2.15
                import QtQuick.Controls 2.0
                
                import "Screen1.qml"
                import "Screen2.qml"
                
                Window {
                    width: 640
                    height: 480
                    visible: true
                    title: qsTr("Sample Project")
                
                    StackView {
                        id: stackView
                        anchors.fill: parent
                        initialItem: screen1
                
                        Component {
                            id: screen1
                            Screen1 {}
                        }
                        Component {
                            id: screen2
                            Screen2 {}
                        }
                
                    }
                
                }
                

                //Screen1.qml

                import QtQuick 2.15
                import QtQuick.Controls 2.0
                
                Item {
                    Text {
                        anchors.centerIn: parent.top
                        text: "Screen1"
                    }
                    Button {
                        text: "Go To Screen2"
                        anchors.centerIn: parent
                        OnClicked: {
                            stackView.push(screen2)
                        }
                    }
                }
                
                

                //Screen2.qml

                import QtQuick 2.15
                import QtQuick.Controls 2.0
                
                Item {
                    Text {
                        anchors.centerIn: parent.Top
                        text: "Screen2"
                    }
                    Button {
                        text: "Go To Screen1"
                        anchors.centerIn: parent
                        OnClicked: {
                            stackView.push(screen1)
                        }
                    }
                }
                
                

                //Error Output

                QML debugging is enabled. Only use this in a safe environment.
                QQmlApplicationEngine failed to load component
                qrc:/main.qml:5:1: "Screen1.qml": no such directory
                
                1 Reply Last reply
                0
                • J jweb1
                  8 Feb 2024, 19:55

                  Hi all,

                  I'm new to QML and Qt, but eager to learn. I'm wanting to use several qml files to reduce the size of my main.qml, however, am having trouble doing so.

                  I'm using a stack view to navigate between screens (in the example below I have a QML file called DiagnosticsScreens.qml at the same file path as my main.qml file).

                  StackView {
                          id: stackView
                          width: 608
                          height: 414
                          x: 96
                          y: 66
                          initialitem: diagnostics_screen
                  
                          Component { id: diagnostics_screen
                              DiagnosticsScreen {}
                          }
                          
                      }
                  

                  When I try to run I get:
                  QQmlApplicationEngine failed to load component
                  qrc:/<folder_name>/main.qml:577:13: DiagnosticsScreen is not a type

                  Any suggestions are greatly appreciated!!!

                  J Offline
                  J Offline
                  jweb1
                  wrote on 20 Feb 2024, 22:14 last edited by
                  #7

                  @jweb1 Resolved!

                  Note: it was a resources folder problem. Thanks all

                  1 Reply Last reply
                  0
                  • J jweb1 has marked this topic as solved on 20 Feb 2024, 22:14

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved