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. No matter what, QT Creator refuses to 'see' the included qml file
QtWS25 Last Chance

No matter what, QT Creator refuses to 'see' the included qml file

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 918 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.
  • N Offline
    N Offline
    niquedegraaff
    wrote on 23 Mar 2023, 23:35 last edited by niquedegraaff
    #1

    I have a very simple barebone project that just opens a window with nothing in it.
    The problem is: It just doesn't want to import the User model qml file. The editor does without any problem. But when I start to built the project, i get these two message:
    QQmlApplicationEngine failed to load component
    qrc:/ui/main.qml:4:1: "../models/user.qml": no such directory qrc:/ui/main.qml: 4

    Why can CT Creator editor find the files without any problem, but the compiler is lost?

    /qml.qrc

    <RCC>
       <qresource prefix="/">
           <file>ui/main.qml</file>
           <file>models/UserModel.qml</file>
       </qresource>
    </RCC>
    

    /models/UserModel.qml

    import QtQuick 2.15
    
    Item {
    
    }
    

    /ui/main.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    
    import "qrc:/models/UserModel.qml" as User
    //import "../models/UserModel.qml" as User // Also doesn't work!
    
    // The main screen
    ApplicationWindow {
        id: window
        width: 800
        height: 600
        visible: true
        title: qsTr("Hello World")
        color: "#1e2433"
        //flags: Qt.Window
    }
    

    /CMakeLists.txt

    cmake_minimum_required(VERSION 3.14)
    
    project(KAuthenticator VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick LinguistTools)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick LinguistTools)
    
    set(TS_FILES KAuthenticator_en_US.ts)
    
    set(PROJECT_SOURCES
        qml.qrc
        src/main.cpp
        i18n/${TS_FILES}
    )
    
    if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
        qt_add_executable(KAuthenticator
            MANUAL_FINALIZATION
            ${PROJECT_SOURCES}
        )
    # Define target properties for Android with Qt 6 as:
    #    set_property(TARGET KAuthenticator APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
    #                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
    # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
    
        qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
    else()
        if(ANDROID)
            add_library(KAuthenticator SHARED
                ${PROJECT_SOURCES}
            )
    # Define properties for Android with Qt 5 after find_package() calls as:
    #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
        else()
            add_executable(KAuthenticator
              ${PROJECT_SOURCES}
            )
        endif()
    
        qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
    endif()
    
    target_link_libraries(KAuthenticator
      PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick)
    
    set_target_properties(KAuthenticator PROPERTIES
        MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    install(TARGETS KAuthenticator
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
    
    if(QT_VERSION_MAJOR EQUAL 6)
        qt_import_qml_plugins(KAuthenticator)
        qt_finalize_executable(KAuthenticator)
    endif()
    
    J K 2 Replies Last reply 24 Mar 2023, 19:34
    0
    • N niquedegraaff
      23 Mar 2023, 23:35

      I have a very simple barebone project that just opens a window with nothing in it.
      The problem is: It just doesn't want to import the User model qml file. The editor does without any problem. But when I start to built the project, i get these two message:
      QQmlApplicationEngine failed to load component
      qrc:/ui/main.qml:4:1: "../models/user.qml": no such directory qrc:/ui/main.qml: 4

      Why can CT Creator editor find the files without any problem, but the compiler is lost?

      /qml.qrc

      <RCC>
         <qresource prefix="/">
             <file>ui/main.qml</file>
             <file>models/UserModel.qml</file>
         </qresource>
      </RCC>
      

      /models/UserModel.qml

      import QtQuick 2.15
      
      Item {
      
      }
      

      /ui/main.qml

      import QtQuick 2.15
      import QtQuick.Window 2.15
      
      import "qrc:/models/UserModel.qml" as User
      //import "../models/UserModel.qml" as User // Also doesn't work!
      
      // The main screen
      ApplicationWindow {
          id: window
          width: 800
          height: 600
          visible: true
          title: qsTr("Hello World")
          color: "#1e2433"
          //flags: Qt.Window
      }
      

      /CMakeLists.txt

      cmake_minimum_required(VERSION 3.14)
      
      project(KAuthenticator VERSION 0.1 LANGUAGES CXX)
      
      set(CMAKE_AUTOUIC ON)
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_AUTORCC ON)
      
      set(CMAKE_CXX_STANDARD 17)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick LinguistTools)
      find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick LinguistTools)
      
      set(TS_FILES KAuthenticator_en_US.ts)
      
      set(PROJECT_SOURCES
          qml.qrc
          src/main.cpp
          i18n/${TS_FILES}
      )
      
      if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
          qt_add_executable(KAuthenticator
              MANUAL_FINALIZATION
              ${PROJECT_SOURCES}
          )
      # Define target properties for Android with Qt 6 as:
      #    set_property(TARGET KAuthenticator APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
      #                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
      # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
      
          qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
      else()
          if(ANDROID)
              add_library(KAuthenticator SHARED
                  ${PROJECT_SOURCES}
              )
      # Define properties for Android with Qt 5 after find_package() calls as:
      #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
          else()
              add_executable(KAuthenticator
                ${PROJECT_SOURCES}
              )
          endif()
      
          qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
      endif()
      
      target_link_libraries(KAuthenticator
        PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick)
      
      set_target_properties(KAuthenticator PROPERTIES
          MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
          MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
          MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
          MACOSX_BUNDLE TRUE
          WIN32_EXECUTABLE TRUE
      )
      
      install(TARGETS KAuthenticator
          BUNDLE DESTINATION .
          LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
      
      if(QT_VERSION_MAJOR EQUAL 6)
          qt_import_qml_plugins(KAuthenticator)
          qt_finalize_executable(KAuthenticator)
      endif()
      
      K Offline
      K Offline
      kkoehne
      Moderators
      wrote on 27 Mar 2023, 07:58 last edited by
      #4

      @niquedegraaff said in No matter what, QT Creator refuses to 'see' the included qml file:

      import "qrc:/models/UserModel.qml" as User

      I don't think this is valid. See e.g. https://doc.qt.io/qt-6/qtqml-syntax-imports.html#import-types ; I think you want to import a directory here.

      Director R&D, The Qt Company

      N 1 Reply Last reply 27 Mar 2023, 09:40
      4
      • N niquedegraaff
        23 Mar 2023, 23:35

        I have a very simple barebone project that just opens a window with nothing in it.
        The problem is: It just doesn't want to import the User model qml file. The editor does without any problem. But when I start to built the project, i get these two message:
        QQmlApplicationEngine failed to load component
        qrc:/ui/main.qml:4:1: "../models/user.qml": no such directory qrc:/ui/main.qml: 4

        Why can CT Creator editor find the files without any problem, but the compiler is lost?

        /qml.qrc

        <RCC>
           <qresource prefix="/">
               <file>ui/main.qml</file>
               <file>models/UserModel.qml</file>
           </qresource>
        </RCC>
        

        /models/UserModel.qml

        import QtQuick 2.15
        
        Item {
        
        }
        

        /ui/main.qml

        import QtQuick 2.15
        import QtQuick.Window 2.15
        
        import "qrc:/models/UserModel.qml" as User
        //import "../models/UserModel.qml" as User // Also doesn't work!
        
        // The main screen
        ApplicationWindow {
            id: window
            width: 800
            height: 600
            visible: true
            title: qsTr("Hello World")
            color: "#1e2433"
            //flags: Qt.Window
        }
        

        /CMakeLists.txt

        cmake_minimum_required(VERSION 3.14)
        
        project(KAuthenticator VERSION 0.1 LANGUAGES CXX)
        
        set(CMAKE_AUTOUIC ON)
        set(CMAKE_AUTOMOC ON)
        set(CMAKE_AUTORCC ON)
        
        set(CMAKE_CXX_STANDARD 17)
        set(CMAKE_CXX_STANDARD_REQUIRED ON)
        
        find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick LinguistTools)
        find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick LinguistTools)
        
        set(TS_FILES KAuthenticator_en_US.ts)
        
        set(PROJECT_SOURCES
            qml.qrc
            src/main.cpp
            i18n/${TS_FILES}
        )
        
        if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
            qt_add_executable(KAuthenticator
                MANUAL_FINALIZATION
                ${PROJECT_SOURCES}
            )
        # Define target properties for Android with Qt 6 as:
        #    set_property(TARGET KAuthenticator APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
        #                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
        # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
        
            qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
        else()
            if(ANDROID)
                add_library(KAuthenticator SHARED
                    ${PROJECT_SOURCES}
                )
        # Define properties for Android with Qt 5 after find_package() calls as:
        #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
            else()
                add_executable(KAuthenticator
                  ${PROJECT_SOURCES}
                )
            endif()
        
            qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
        endif()
        
        target_link_libraries(KAuthenticator
          PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick)
        
        set_target_properties(KAuthenticator PROPERTIES
            MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
            MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
            MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
            MACOSX_BUNDLE TRUE
            WIN32_EXECUTABLE TRUE
        )
        
        install(TARGETS KAuthenticator
            BUNDLE DESTINATION .
            LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
        
        if(QT_VERSION_MAJOR EQUAL 6)
            qt_import_qml_plugins(KAuthenticator)
            qt_finalize_executable(KAuthenticator)
        endif()
        
        J Offline
        J Offline
        JoeCFD
        wrote on 24 Mar 2023, 19:34 last edited by JoeCFD
        #2

        @niquedegraaff the path of your ../models/user.qml may not be used properly.

        find the file
        qrc_qml.cpp
        in the build dir something like build/KAuthenticator_autogen/3YJK5W5UP7
        and open it in an editor. Scroll all way to the end and check the path definition for it in
        static const unsigned char qt_resource_struct[] ={
        }.
        Use that path in your code.

        N 1 Reply Last reply 27 Mar 2023, 07:48
        0
        • J JoeCFD
          24 Mar 2023, 19:34

          @niquedegraaff the path of your ../models/user.qml may not be used properly.

          find the file
          qrc_qml.cpp
          in the build dir something like build/KAuthenticator_autogen/3YJK5W5UP7
          and open it in an editor. Scroll all way to the end and check the path definition for it in
          static const unsigned char qt_resource_struct[] ={
          }.
          Use that path in your code.

          N Offline
          N Offline
          niquedegraaff
          wrote on 27 Mar 2023, 07:48 last edited by
          #3

          @JoeCFD
          The path in that file is correctly
          // :/models/UserModel.qml

          And that's correct. So I don't understand why it is trying to get /models/user.qml. Weird behavior.

          1 Reply Last reply
          0
          • N niquedegraaff
            23 Mar 2023, 23:35

            I have a very simple barebone project that just opens a window with nothing in it.
            The problem is: It just doesn't want to import the User model qml file. The editor does without any problem. But when I start to built the project, i get these two message:
            QQmlApplicationEngine failed to load component
            qrc:/ui/main.qml:4:1: "../models/user.qml": no such directory qrc:/ui/main.qml: 4

            Why can CT Creator editor find the files without any problem, but the compiler is lost?

            /qml.qrc

            <RCC>
               <qresource prefix="/">
                   <file>ui/main.qml</file>
                   <file>models/UserModel.qml</file>
               </qresource>
            </RCC>
            

            /models/UserModel.qml

            import QtQuick 2.15
            
            Item {
            
            }
            

            /ui/main.qml

            import QtQuick 2.15
            import QtQuick.Window 2.15
            
            import "qrc:/models/UserModel.qml" as User
            //import "../models/UserModel.qml" as User // Also doesn't work!
            
            // The main screen
            ApplicationWindow {
                id: window
                width: 800
                height: 600
                visible: true
                title: qsTr("Hello World")
                color: "#1e2433"
                //flags: Qt.Window
            }
            

            /CMakeLists.txt

            cmake_minimum_required(VERSION 3.14)
            
            project(KAuthenticator VERSION 0.1 LANGUAGES CXX)
            
            set(CMAKE_AUTOUIC ON)
            set(CMAKE_AUTOMOC ON)
            set(CMAKE_AUTORCC ON)
            
            set(CMAKE_CXX_STANDARD 17)
            set(CMAKE_CXX_STANDARD_REQUIRED ON)
            
            find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick LinguistTools)
            find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick LinguistTools)
            
            set(TS_FILES KAuthenticator_en_US.ts)
            
            set(PROJECT_SOURCES
                qml.qrc
                src/main.cpp
                i18n/${TS_FILES}
            )
            
            if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
                qt_add_executable(KAuthenticator
                    MANUAL_FINALIZATION
                    ${PROJECT_SOURCES}
                )
            # Define target properties for Android with Qt 6 as:
            #    set_property(TARGET KAuthenticator APPEND PROPERTY QT_ANDROID_PACKAGE_SOURCE_DIR
            #                 ${CMAKE_CURRENT_SOURCE_DIR}/android)
            # For more information, see https://doc.qt.io/qt-6/qt-add-executable.html#target-creation
            
                qt_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
            else()
                if(ANDROID)
                    add_library(KAuthenticator SHARED
                        ${PROJECT_SOURCES}
                    )
            # Define properties for Android with Qt 5 after find_package() calls as:
            #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
                else()
                    add_executable(KAuthenticator
                      ${PROJECT_SOURCES}
                    )
                endif()
            
                qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
            endif()
            
            target_link_libraries(KAuthenticator
              PRIVATE Qt${QT_VERSION_MAJOR}::Core Qt${QT_VERSION_MAJOR}::Quick)
            
            set_target_properties(KAuthenticator PROPERTIES
                MACOSX_BUNDLE_GUI_IDENTIFIER my.example.com
                MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
                MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
                MACOSX_BUNDLE TRUE
                WIN32_EXECUTABLE TRUE
            )
            
            install(TARGETS KAuthenticator
                BUNDLE DESTINATION .
                LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
            
            if(QT_VERSION_MAJOR EQUAL 6)
                qt_import_qml_plugins(KAuthenticator)
                qt_finalize_executable(KAuthenticator)
            endif()
            
            K Offline
            K Offline
            kkoehne
            Moderators
            wrote on 27 Mar 2023, 07:58 last edited by
            #4

            @niquedegraaff said in No matter what, QT Creator refuses to 'see' the included qml file:

            import "qrc:/models/UserModel.qml" as User

            I don't think this is valid. See e.g. https://doc.qt.io/qt-6/qtqml-syntax-imports.html#import-types ; I think you want to import a directory here.

            Director R&D, The Qt Company

            N 1 Reply Last reply 27 Mar 2023, 09:40
            4
            • N niquedegraaff has marked this topic as solved on 27 Mar 2023, 09:40
            • K kkoehne
              27 Mar 2023, 07:58

              @niquedegraaff said in No matter what, QT Creator refuses to 'see' the included qml file:

              import "qrc:/models/UserModel.qml" as User

              I don't think this is valid. See e.g. https://doc.qt.io/qt-6/qtqml-syntax-imports.html#import-types ; I think you want to import a directory here.

              N Offline
              N Offline
              niquedegraaff
              wrote on 27 Mar 2023, 09:40 last edited by
              #5

              @kkoehne
              Ah, I see. Thank you

              1 Reply Last reply
              0

              4/5

              27 Mar 2023, 07:58

              • Login

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