Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-100869

Qml in plugin: Cannot resolve import ".."

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • 6.x
    • 6.3.0 Beta2
    • QML: Tooling
    • macOS

    Description

      The attached example program tries to put its Qml files into a "ui" plugin. Motivation is to avoid having the .qml files on the same level as the project's main CMakeLists.txt.

      Running the code results in this error message:

      QQmlApplicationEngine failed to load component
      qrc:/ui/main.qml:22:5: Type FooText unavailable
      qrc:/ui/controls/FooText.qml:3:1: module ":.ui" plugin "uiplugin" not found
      
      • Is there anything wrong with using import ".."? Real life code is full of those imports.
      • Using import ".." without the code being bundled in a separate plugin (without the ui subdirectory, using the application target directly) works.

      ui/controls/FooText.qml

      import QtQuick
      
      import ".."   // << error message
      
      GreenText {
        color: "red"
      }
      

       
      ui/CMakeLists.txt

      cmake_minimum_required(VERSION 3.16)
      
      qt_add_library(ui STATIC)
      
      qt_add_qml_module(ui
          URI ui
          VERSION 1.0
          QML_FILES
            main.qml
            GreenText.qml
            controls/BlueText.qml
            controls/FooText.qml
      )
      

      CMakeLists.txt

      cmake_minimum_required(VERSION 3.16)
      
      project(untitled11 VERSION 0.1 LANGUAGES CXX)
      
      set(CMAKE_AUTOMOC ON)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)
      
      find_package(Qt6 6.2 COMPONENTS Quick REQUIRED)
      
      qt_add_executable(appuntitled11
          main.cpp
      )
      
      # Qml UI
      add_subdirectory(ui)
      
      set_target_properties(appuntitled11 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
      )
      
      target_compile_definitions(appuntitled11
          PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
      target_link_libraries(appuntitled11
          PRIVATE
            Qt6::Quick
            uiplugin
          )
      

      Attachments

        1. untitled11_v2.tgz
          1 kB
          Nils Jeisecke
        2. untitled11.tgz
          1 kB
          Nils Jeisecke

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qtqmlteam Qt Qml Team User
              njeisecke Nils Jeisecke
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes