Qt6 + Gstreamer + CMake
-
Cheers!
Trying to implement some desktop app that will have embedded video player, which will get video stream through rtp,rtsp or something similar.
I found the example project (https://gitlab.freedesktop.org/gstreamer/gstreamer/-/tree/main/subprojects/gst-plugins-good/tests/examples/qt6/qmlsink?ref_type=heads), built it, launched and everything goes smooth.
Then I created CMake project file in the same directory(because I'm not quite familiar with qmake, on top of that whole ecosystem(dozen of projects so far) use CMake), built it, launched and everything goes smooth once again!Now I created new empty QT desktop App project, copy paste CMake file, added minor changes to process ui, moc whatever.
Built it, launched and got error:QQmlApplicationEngine failed to load component qrc:/VideoPlayer.qml:32:1: module "org.freedesktop.gstreamer.Qt6GLVideoItem" is not installed [DBG] QML import paths: "/home/user/code/project/build" "qrc:/qt-project.org/imports" "qrc:/qt/qml" "/usr/lib/qt6/qml"
For some incomprehensible reasons, it now can't find qml module! I also added printf to get path it looked, and it's identical to those that the example app used.
CMake:
cmake_minimum_required(VERSION 3.14) project(NewAppGstreamer) set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) # Set the C++ standard set(CMAKE_CXX_STANDARD 17) # Find Qt6 find_package(Qt6 REQUIRED COMPONENTS Core Quick Qml Widgets) # Find GStreamer using pkg-config find_package(PkgConfig REQUIRED) pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0 gstreamer-video-1.0) # Add additional include path for GStreamer include_directories(${GSTREAMER_INCLUDE_DIRS} ../lib) # Define the preprocessor macro (equivalent to DEFINES) add_definitions(-DGST_USE_UNSTABLE_API) qt_add_resources(RESOURCE_FILES resources.qrc) # Create the executable # add_executable(NewAppGstreamer main.cpp) qt_add_executable(NewAppGstreamer mainwindow.cpp mainwindow.ui mainwindow.h main.cpp ${RESOURCE_FILES} ) # Set up the QML resource file # qt_add_resources(NewAppGstreamer "RESOURCES" qmlsink.qrc) # Link the executable to Qt6 and GStreamer target_link_libraries(NewAppGstreamer PRIVATE Qt6::Core Qt6::Quick Qt6::Qml Qt6::Widgets ${GSTREAMER_LIBRARIES} ) # Ensure pkg-config is used for the build set(PKG_CONFIG_EXECUTABLE ${PkgConfig_EXECUTABLE}) # Set the QML import path (if needed) # Set your custom import paths if required # set(QML_IMPORT_PATH "/path/to/your/qml/modules") # Set the GST_PLUGIN_PATH environment variable # This ensures GStreamer can find its plugins set(ENV{GST_PLUGIN_PATH} "/usr/lib/gstreamer-1.0") # Ensure Qt6 QML import path is included in the build process target_compile_definitions(NewAppGstreamer PRIVATE QT_QML_IMPORT_PATH="${QML_IMPORT_PATH}")
drwxr-xr-x - user 10 кві 11:55 build .rw-r--r-- 1,6k user 10 кві 11:55 CMakeLists.txt .rw-r--r-- 34k user 9 кві 18:39 CMakeLists.txt.user .rw-r--r-- 525 user 9 кві 17:27 main.cpp .rw-r--r-- 2,6k user 9 кві 18:07 mainwindow.cpp .rw-r--r-- 632 user 9 кві 17:32 mainwindow.h .rw-r--r-- 998 user 9 кві 14:04 mainwindow.ui .rw-r--r-- 94 user 9 кві 16:51 resources.qrc .rw-r--r-- 2,8k user 10 кві 11:40 VideoPlayer.qml
cat resources.qrc <RCC> <qresource prefix="/"> <file>VideoPlayer.qml</file> </qresource> </RCC>
QML file is copy of the one from the example prject
Now I'm lost, CMake file is pretty much the same, and I have no idea what could potentially lead to such a behavior.
Any help is appreciated, I'm new to Qt world.
Thanks in advance! -
The error does not mean qml module can not be found. Instead gstreamer good plug-in(has qml sink) can not be found.
Note(from the example code):
/* the plugin must be loaded before loading the qml file to register the
* GstGLVideoItem qml item */
GstElement *sink = gst_element_factory_make ("qml6glsink", NULL);It can be deleted immediately since its only purpose is to load gstreamer good plug-in.
I prefer to add gstreamer libs as follows:
target_link_libraries(NewAppGstreamer PRIVATE Qt6::Core Qt6::Quick Qt6::Qml Qt6::Widgets PkgConfig::GSTREAMER PkgConfig::GSTREAMER-VIDEO )
-