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. Qt5 QML Unknown component
Forum Updated to NodeBB v4.3 + New Features

Qt5 QML Unknown component

Scheduled Pinned Locked Moved Solved QML and Qt Quick
7 Posts 2 Posters 599 Views 1 Watching
  • 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.
  • P Offline
    P Offline
    PDLAOZEI
    wrote on last edited by
    #1

    Because of the need of work, I changed build system from qmake to cmake.
    I found a problem that the program works properly, but calls MyRectangle.qml under other files in main.qml to prompt Unknown component. (M300),
    On qmake, this problem does not exist as long as qrc is prefixed with "/". just like this
    95cad0f5-680b-4d74-975d-a34762c3c8f0-image.png
    what should I do?

    Qt version: Qt 5.15.2
    Build system: CMake

    cmake_minimum_required(VERSION 3.14)
    
    project(untitled VERSION 0.1 LANGUAGES CXX)
    
    ......
    
    find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core Quick)
    find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core Quick)
    
    set(PROJECT_SOURCES
            main.cpp
            qml.qrc
            ./Extend/extend.qrc
    )
    
    if(${QT_VERSION_MAJOR} GREATER_EQUAL 6)
        qt_add_executable(untitled
            MANUAL_FINALIZATION
            ${PROJECT_SOURCES}
        )
    ......
    
    

    The structure of the whole project is shown in the figure
    c4bcbfcf-85ed-435d-8211-4ecbaef4a070-image.png

    main.qml

    import QtQuick 2.15
    import QtQuick.Window 2.15
    
    Window {
        width: 640
        height: 480
        visible: true
        MyRectangle{                          ----- UnKnown component. (M300)
            anchors.fill: parent
        }
    }
    

    MyRectangle.qml

    import QtQuick 2.15
    import QtQuick.Controls 2.15
    
    Rectangle {
        Label{
            anchors.centerIn: parent
            text: "hello world"
        }
    }
    

    I have tried to add qrc files using qt5_add_resources,and try Tools > QML/JS > Reset Code Model but the problem still exists
    In my opinion, Maybe it's a good idea for me to use QML_DIR to turn qml into a module?
    Thanks....

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #4

      Yup, that's pretty normal. Qt Creator is not very clever when it comes to QML and custom components.

      (Z(:^

      P 1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #2

        So the app works fine, and only in Qt Creator you get this M300 warning? I just ignore this.

        (Z(:^

        P 1 Reply Last reply
        0
        • sierdzioS sierdzio

          So the app works fine, and only in Qt Creator you get this M300 warning? I just ignore this.

          P Offline
          P Offline
          PDLAOZEI
          wrote on last edited by
          #3

          @sierdzio Yes, according to the above code, you can see.

          9b3262a0-251c-48b8-8859-81343c341e36-image.png

          In fact, the code cannot use ctrl + click to jump to the corresponding file and provide any hints

          1 Reply Last reply
          0
          • sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by
            #4

            Yup, that's pretty normal. Qt Creator is not very clever when it comes to QML and custom components.

            (Z(:^

            P 1 Reply Last reply
            0
            • sierdzioS sierdzio

              Yup, that's pretty normal. Qt Creator is not very clever when it comes to QML and custom components.

              P Offline
              P Offline
              PDLAOZEI
              wrote on last edited by
              #5

              @sierdzio i see, Can I avoid this if I use a higher version of qt or other methods?

              1 Reply Last reply
              0
              • sierdzioS Offline
                sierdzioS Offline
                sierdzio
                Moderators
                wrote on last edited by
                #6

                I don't know, I'm also stuck on Qt 5 ;-)

                (Z(:^

                P 1 Reply Last reply
                0
                • sierdzioS sierdzio

                  I don't know, I'm also stuck on Qt 5 ;-)

                  P Offline
                  P Offline
                  PDLAOZEI
                  wrote on last edited by
                  #7

                  @sierdzio Thank you for your answer to solve my doubts.
                  I think we can try qmldir or discuss with colleagues about switching the project back to use qmake. XD

                  1 Reply Last reply
                  0
                  • P PDLAOZEI has marked this topic as solved on

                  • Login

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