Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to add a QML file we wrote to another QML file
Forum Updated to NodeBB v4.3 + New Features

How to add a QML file we wrote to another QML file

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 422 Views 2 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.
  • serkan_trS Offline
    serkan_trS Offline
    serkan_tr
    wrote on last edited by serkan_tr
    #1

    Hi,
    I have two qml files and I am trying to import one into the other but it gives an error.

    file production:
    65ca288d-9de0-45ff-bd07-7439a2d94392-image.png

    cmake file:

    cmake_minimum_required(VERSION 3.16)
    
    project(conveyor VERSION 0.1 LANGUAGES CXX)
    
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    find_package(Qt6 6.4 REQUIRED COMPONENTS Quick)
    
    qt_standard_project_setup()
    
    qt_add_executable(appconveyor
        main.cpp
    )
    
    qt_add_qml_module(appconveyor
        URI conveyor
        VERSION 1.0
        QML_FILES
            qml/Main.qml
            qml/MyMainToolbar.qml
    )
    
    set_target_properties(appconveyor PROPERTIES
    #    MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appconveyor
        MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
        MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
        MACOSX_BUNDLE TRUE
        WIN32_EXECUTABLE TRUE
    )
    
    target_link_libraries(appconveyor PRIVATE Qt6::Quick)
    
    install(TARGETS appconveyor
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
    
    target_link_libraries(appconveyor
        PRIVATE Qt6::Quick
    )
    
    include(GNUInstallDirs)
    install(TARGETS appconveyor
        BUNDLE DESTINATION .
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
        RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    )
    
    

    main.qml
    e3c315ad-f132-4f45-b587-49003be6fbe3-image.png

    MyMainToolbar.qml:

    import QtQuick 2.15
    
    Item {
        id: root
    
        Rectangle {
            height: 50
            width: 100
            color: "blue"
        }
    }
    

    Why doesn't my QML file appear in this section?

    I can go to the location of the file using Ctrl, but when I run the file it gives an error
    a7e8fae2-182c-4696-9a97-5bd28f214083-image.png

    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #5

      The import name of your module is conveyor as defined in the URI of qt_add_qml_module.

      Use import conveyor.

      1 Reply Last reply
      1
      • A Offline
        A Offline
        ankou29666
        wrote on last edited by
        #2

        your toolbar is just a simple component, not a module, thus you don't have to import it.
        Simply just remove the import MyMainToolBar statement in your main.qml and the error message will disappear.

        1 Reply Last reply
        0
        • serkan_trS Offline
          serkan_trS Offline
          serkan_tr
          wrote on last edited by
          #3

          @ankou29666 Yes, but my purpose in this section is to import the QML files I wrote and use the features in the QML file I imported. If I remove import MyMainToolBar, can I access the codes in MyMainToolBar?

          jsulmJ 1 Reply Last reply
          0
          • serkan_trS serkan_tr

            @ankou29666 Yes, but my purpose in this section is to import the QML files I wrote and use the features in the QML file I imported. If I remove import MyMainToolBar, can I access the codes in MyMainToolBar?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #4

            @serkan_tr said in How to add a QML file we wrote to another QML file:

            If I remove import MyMainToolBar, can I access the codes in MyMainToolBar?

            Why don't you try?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • GrecKoG Offline
              GrecKoG Offline
              GrecKo
              Qt Champions 2018
              wrote on last edited by
              #5

              The import name of your module is conveyor as defined in the URI of qt_add_qml_module.

              Use import conveyor.

              1 Reply Last reply
              1
              • serkan_trS serkan_tr 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