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

QML Module not found (QtMultimedia)



  • I am getting this error while trying to use a Video QML type from QtMultimedia. I have tried everything I can think of.

    I am using Qt 5.12, Qt Creator 4.9.0, C++ 17, and CMake 3.13

    QML file
    Error displayed in Qt Creator

    CMakeLists.txt

    ...
    
    set(CMAKE_CXX_STANDARD 17)
    
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTORCC ON)
    set(CMAKE_CXX_STANDARD 17)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
    set(Qt5_DIR "/usr/local/opt/qt/lib/cmake/Qt5")
    
    find_package(Qt5 COMPONENTS Core Quick Widgets Multimedia REQUIRED)
    
    set(SRC_FILES main.cpp backend.h backend.cpp)
    set(QML_FILES qml/BackButton.qml qml/DecodeView.qml qml/EncodeView.qml qml/FileLoader.qml main.qml qml/SubtitleView.qml qml/videoTranscription.qml)
    set(RES_FILES qml.qrc resources/icon.icns resources/logo_transparent.png)
    
    add_executable(${PROJECT_NAME} ${SRC_FILES} ${QML_FILES} ${RES_FILES})
    target_compile_definitions(${PROJECT_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
    target_link_libraries(${PROJECT_NAME} PRIVATE Qt5::Core Qt5::Quick Qt5::Widgets Qt5::Multimedia)
    
    ...
    

    I tried to set the QML_IMPORT_PATH to the location of QtMultimedia but to no avail

    QML_IMPORT_PATH

    set(QML_IMPORT_PATH ${CMAKE_SOURCE_DIR}/qml ${CMAKE_BINARY_DIR}/imports /usr/local/opt/qt/lib/ CACHE STRING "" FORCE)
    

  • Moderators

    Hi @bob_harris
    and welcome.

    I' ve little experience with cmake, so I can't give you a 100% straight answer. But I'm pretty sure what the issue is and how you could fix it. But if no-one else can help you more directly, it should point you in the correct direction.

    QtMultimedia is it's own module. In qmake you would simply write QT += multimedia to link against it.
    cmake has qt5_use_modules(target [LINK_PUBLIC|LINK_PRIVATE] module ... )
    see here for more information
    https://doc.qt.io/qt-5/cmake-manual.html#module-variables



  • That qt5_use_modules() is fairly confusing. It states the macro is obsolete and target_link_libraries should be used instead.

    Regardless I managed to fix this, QtCreator was defaulting to a version of Qt that CMake wasn't using.

    I changed this by manually adding the location of the Homebrew installed version of Qt to QtCreator.


Log in to reply