How to add a QML file we wrote to another QML file
-
Hi,
I have two qml files and I am trying to import one into the other but it gives an error.file production:

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

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

-
The import name of your module is
conveyoras defined in the URI ofqt_add_qml_module.Use
import conveyor. -
your toolbar is just a simple component, not a module, thus you don't have to import it.
Simply just remove theimport MyMainToolBarstatement in your main.qml and the error message will disappear. -
@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? -
@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?@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?
-
The import name of your module is
conveyoras defined in the URI ofqt_add_qml_module.Use
import conveyor. -
S serkan_tr has marked this topic as solved on