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. Qt Quick QML Unit Test linkage problem
Qt 6.11 is out! See what's new in the release blog

Qt Quick QML Unit Test linkage problem

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 225 Views
  • 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.
  • H Offline
    H Offline
    HFL99
    wrote on last edited by
    #1

    I am trying to create unit tests for a practice Qt Quick QML project on Qt 5.12 using Qmake configuration on ubuntu and I am running into problem on how to make my test files able to find and import my custom components in order to test for them.

    In my Tests subdir, the .pro file looks like this:

    CONFIG += warn_on qmltestcase testlib
    
    INCLUDEPATH = $$PWD/../app
    
    IMPORTPATH += $$PWD/../app
    
    QML_IMPORT_PATH += $$PWD/../app
    
    TEMPLATE = app
    
    TARGET = tst_example
    
    DISTFILES += \
        tst_MoviePlayer.qml
    
    SOURCES += \
        main.cpp
    

    As you can see, I tried INCLUDEPATH, IMPORTPATH, and QML_IMPORT_PATH to point at the parent-directory/app folder where the custom component .qml is at.

    The structure is like this:

    |- MyProject.pro
        | - app
            |- main.qml
            |- main.pro
            |- main.cpp
            |- MoviePlayer.qml
            |- qml.qrc
        | - tests
            |- test.pro
            |- main.cpp
            |- tst_MoviePlayer.qml
    

    When I go in tst_MoviePlayer.qml and try this:

    TestCase {
        function test_MoviePlayer() {
            var moviePlayer = createTemporaryQmlObject("import MoviePlayer 1.0; MoviePlayer {}", this)
        }
    }
    

    It says MoviePlayer module is not installed. I also tried just createTemporaryQmlObject("MoviePlayer {}", this) and get "MoviePlayer is not a type" error.

    I added a .qrc file with the following structure and I was able to create a MoviePlayer type inside my tests qml files, however I still cannot createTemporaryQmlObject because it still says 'MoviePlayer is not a type' even though I can declare a MoviePlayer type just fine in the very same file?

    <RCC>
        <qresource prefix="/">
            <file>tst_MoviePlayer.qml</file>
            <file alias="MoviePlayer.qml">../app/MoviePlayer.qml</file>
        </qresource>
    </RCC>
    
    1 Reply Last reply
    0

    • Login

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