Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Cant able to access qml file from source project into Qt Quick Test project



  • I have a source project which contains some QML files. I wanted to apply unit testing on that QML files by creating different Qt Quick test project. Thats why I am trying to access that QML file from source project into Qt Quick Test project.

    Following is my project structure:

    MainProject
          - CMakeLists.txt
          - src
                 - CMakeLists.txt
                 - main.cpp
                 - qml.qrc
                           - MyWindow.qml
          - QuickTest
                 - CMakeLists.txt
                 - main.cpp
                 - qml.qrc
                           - tst_mywindow.qml
    

    Now I am trying to access the component from MyWindow file into tst_mywindow file to apply unit testing on it. I tried to link both projects using various ways but didn't work. The ways I tried

    set(QML_IMPORT_PATH "${CMAKE_SOURCE_DIR}/src/MyWindow.qml")
    
    add_executable(QuickTest
        main.cpp
        ${CMAKE_SOURCE_DIR}/src/MyWindow.qml
        qml.qrc)
    
    target_sources(QuickTest
    PRIVATE
        ${CMAKE_SOURCE_DIR}/src/MyWindow.qml
    )
    

    Please tell me any way so I can access that qml file in my test project. Thanks in advance.