How can I resolve “QML module not found” within Qt Creator - qt

This question is related to the unanswered “Display video in Qml via Gstreamer qmlglsink plugin” question as I have the same problem.
The issue is that Qt Creator cannot find whatever file is necessary to resolve the import “org.freedesktop.gstreamer.GLVideoItem 1.0” statement.
When I create a new QML project and add the import “org.freedesktop.gstreamer.GLVideoItem 1.0” line. I get this error. The project compiles and runs fine.
I have another project taken from an example I downloaded. It uses GstGLVideoItem within its qml file. It also gives the same error and it also compiles and runs fine. It plays the Big Buck Bunny video from a file without issue.
I have totally rebuilt my computer trying to resolve this. Reinstalled Qt 5.15.2 using the online installer and GStreamer 1.18.0 following the instructions on the GStreamer website into an Ubuntu 20.10 PC. Both Qt and GStreamer are working as expected. I have been able to build and run any desired Qt Example without issue. I have also been able to compile and run any of the GStreamer tutorials as well as my own custom pipelines using C and gst-launch-1.0.
This issue occurs within Qt Creator when I bring the two together and try to display a GStreamer video in QML.
I’m new to Linux, Qt, GStreamer, qmake, cmake… How can I debug this? What kind of file is the import statement looking for? Is it a .qml file or some other kind of file? How would I find the files exact name to see if it exists?
Here is the contents of the .pro file for the project that displays the video. I have tried most everything I can find online to resolve this, but no joy.
TEMPLATE = app
QT += qml quick widgets
CONFIG += qml_debug
QT_CONFIG -= no-pkg-config
CONFIG += link_pkgconfig debug
PKGCONFIG += \
gstreamer-1.0 \
gstreamer-sdp-1.0 \
gstreamer-gl-prototypes-1.0 \
gstreamer-gl-1.0 \
gstreamer-gl-egl-1.0 \
gstreamer-app-1.0 \
gstreamer-net-1.0 \
gstreamer-video-1.0 \
gstreamer-controller-1.0 \
gstreamer-rtsp-1.0 \
gstreamer-plugins-base-1.0 \
gstreamer-pbutils-1.0 \
gstreamer-check-1.0 \
gstreamer-allocators-1.0 \
gstreamer-rtp-1.0 \
gstreamer-riff-1.0 \
gstreamer-tag-1.0 \
gstreamer-audio-1.0 \
gstreamer-gl-x11-1.0 \
gstreamer-fft-1.0 \
gstreamer-base-1.0
CONFIG += c++17
INCLUDEPATH += /usr/include/gstreamer-1.0/
INCLUDEPATH += /usr/include/glib-2.0/
INCLUDEPATH += /usr/lib/x86_64-linux-gnu/glib-2.0/include/
DEFINES += GST_USE_UNSTABLE_API
INCLUDEPATH += ../lib
SOURCES += main.cpp \
qmlplayer.cpp \
setplaying.cpp
RESOURCES += qmlsink.qrc
QML_IMPORT_PATH += /usr/lib/x86_64-linux-gnu/gstreamer-1.0
QML_IMPORT_PATH += /usr/lib/x86_64-linux-gnu/gstreamer1.0/gstreamer-1.0
QML_IMPORT_PATH += /lib/x86_64-linux-gnu/gstreamer-1.0
HEADERS += \
qmlplayer.h \
setplaying.h

Matthew Waters on the GStreamer forum has answered this question.
I quote him below.
Ah, so your problem is use with the Qt designer not showing finding the
relevant qml code. That use case is currently not supported by qmlglsink.
The issue is that the necessary QML item is contained within the
qmlglsink element itself and is registered dynamically when the element
itself is instantiated. Qt designer doesn't know anything about
GStreamer so cannot perform this initialisation for you. There are no
qmldir or qmltype files for qmlglsink.
The 'fix' involves are rather complicated restructure of the qmlglsink
element to support placing the qml part/plugin in a separate .so that is
findable with Qt tools (using qmldir or whatever).

You might have to dynamicaly register the module before loading the qml on your main as below.
qmlRegisterType<QtGLVideoItem> ("org.freedesktop.gstreamer.GLVideoItem", 1, 0, "GstGLVideoItem");
You will have to create the QtGLVideoItem object which inherits the QtQuickItem class, please see below.
#include <QQuickItem>
class QtGLVideoItem : public QQuickItem
{
Q_OBJECT
public:
QtGLVideoItem();
~QtGLVideoItem();
protected:
private:
};

Related

Building a Qt module from source and use it

I've downloaded Qt from sources and thus I have the qt-everywhere-opensource-src folder containing all the Qt modules.
I needed to edit the bluetooth module, so I customized the QtConnectivity module (which contains Bluetooth and NFC APIs), and when building it, I'm getting .so and .a files.
Now my question is, how to use this new bluetooth library in a Qt project ?
1. Replace Qt files in Qt installation folder - Working
I've tried to put my generated libraries directly in my Qt sources, so I replaced original Qt files in C:\Qt\5.9.6\android_armv7\lib with my .so files for Android, and it is working great.
In my .pro, just with QT += bluetooth, everythings builds correctly, and in my application, I can access to my new functions.
2. Import library as standalone library - Not working
I've tried many ways to add bluetooth from my new sources, but none of them worked, here are some QMake variables I tried to set :
ANDROID_BUNDLED_JAR_DEPENDENCIES += \
$$PWD/mylib/src/bluetooth/jar/QtAndroidBluetooth-bundled.jar
ANDROID_JAR_DEPENDENCIES += \
$$PWD/mylib/src/bluetooth/jar/QtAndroidBluetooth.jar
ANDROID_LIB_DEPENDENCIES += \
$$PWD/mylib/lib/android/libMyLib.so
ANDROID_PERMISSIONS += \
android.permission.BLUETOOTH \
android.permission.BLUETOOTH_ADMIN
LIBS += -L$$PWD/mylib/lib/ -lMyLib

QML doesn't show svg images

I wrote a simple QML ui that is using some svg images.
When I execute the app on my desktop everything is fine, the UI is shown and also the svg images on it.
The problem happens when I try to execute the app on an embedded device (running windows embedded). In this case the UI is displayed but the svg images are not shown and on the console I'm getting the following message:
QML BorderImage: Invalid image data: my_image.svg
The png images are shown correctly instead.
I research the problem over the Internet and I've found a lot of ppl that had solve the issue by adding svg and other dependencies to the .pro file.
Unfortunately this didn't help in my case.
Those are the contents of my .pro file:
TEMPLATE = app
QT += qml quick widgets svg xml gui core
QTPLUGIN += qsvg
SOURCES += main.cpp \
SignalProcessor.cpp \
PopupMode.cpp \
BasicToolbarModel.cpp
RESOURCES += qml.qrc
# Additional import path used to resolve QML modules in Qt Creator's code model
QML_IMPORT_PATH =
# Default rules for deployment.
include(deployment.pri)
HEADERS += \
SignalProcessor.h \
PopupMode.h \
BasicToolbarModel.h
CONFIG += qmltestcase
QUICK_TEST_SOURCE_DIR += Tests
DISTFILES += \
qml/main.qml \
qml/CustomToolBar.qml \
qml/components/BatteryStatus.qml \
qml/components/ImageButton.qml \
qml/components/Popup.qml \
qml/components/WifiStatus.qml \
qml/pages/PlayButtonView.qml \
qml/pages/StopButtonView.qml \
qml/tests/tst_CustomToolBar.qml \
qml/tests/tst_WifiStatus.qml \
scripts/Utils.js
Edit: all the svg images are located inside the resource file
In order to display an SVG image, I've done the following :
Added svg to the .pro file :
QT += svg
Ensured that my Image had a size :
height: 400
width: 400
Ensured that I set the source SVG a size :
sourceSize.width: 100
sourceSize.height: 100
That's all.
When I have forgotten things in my QML file, I have had warnings like :
W/libnotification.so( 3800): (null):0 ((null)): QOpenGLShaderProgram: could not create shader program
W/libnotification.so( 3800): (null):0 ((null)): QOpenGLShader: could not create shader
After fixing the QML, the emulator was still complaining :
E/OpenGLRenderer( 4435): GL error: GL_INVALID_VALUE
I had to restart the emulator in order to have it display something again.
Tip : in order to have a correct visual quality, do not set sourceSize too low compared to the Image size (the above example can give ugly results because of the x4 factor).
(I'm testing with Qt 5.7 on an Android emulator).
As documentation says:
Qt comes with a number of plugins which are loaded at run-time when they are needed. These can handle anything from connecting to SQL databases to loading specific image formats. Detecting plugin dependencies is impossible as the plugins are loaded at run-time, but androiddeployqt tries to guess such dependencies based on the Qt dependencies of your application. If the plugin has any Qt dependencies which are not also dependencies of your application, it will not be included by default. For instance, in order to ensure that the SVG image format plugin is included, you will need to add QT += svg to your .pro file so that the Qt SVG module becomes a dependency of your application.
You need to indicating plugin dependencies using .pro file.
Maybe some shared libraries are missed.
Accordingly to the documentation, on Windows (I guess even on WinCE) you have to deploy all the required dll along with your application.
Here is an interesting page on the topic from the wiki.
Here you can find a similar question on that site.
This one is another resource which could be helpful.
I solved similar issue by adding qsvgicon to QTPLUGIN:
QTPLUGIN += qsvg qsvgicon
It was QWidget application, but I think this solution should help.
You need to include these lines in your .pro file
QT += xml svg
QTPLUGIN += qsvg

undefined reference qt opencv

I am new to Qt and openCV, and i try to make a simple project with code:
in the .pro:
QT += core
QT -= gui
QT += widgets
TARGET = latihan_2
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += E:\\OpenCV\\OpenCV\\opencv\\build\\include
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\vc10\lib\opencv_core246.lib
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\vc10\lib\opencv_highgui246.lib
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\vc10\lib\opencv_imgproc246.lib
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\vc10\lib\opencv_features2d246.lib
LIBS += E:\OpenCV\OpenCV\opencv\build\x86\vc10\lib\opencv_calib3d246.lib
in the main.cpp:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main(){
//read image
cv::Mat image;
image = cv::imread("img.jpg");
//create image window named "My image"
cv::namedWindow("My Image");
//show the image on window
cv::imshow("My image", image);
//wait key for 5000ms
cv::waitKey(5000);
return 1;
}
however, it always give error about the undefined reference to cv::imread, cv::namedWindows, and the other CV functions i used.
i use Qt creator 2.8.1, based on Qt 5.1.1, and openCV-2.4.6.0
Any help would be greatly appreciated!
thanks
undefined reference errors are a linking problem, which means that your project compiled successfully but the linker is unable to find the binary code for those functions.
I have a very simple OpenCV/Qt project that is setup to be compiled on Windows/Linux/Mac OS X. If you take a look at the .pro file, you'll notice that for Windows I do:
win32 {
message("* Using settings for Windows.")
INCLUDEPATH += "C:\\opencv\\build\\include" \
"C:\\opencv\\build\\include\\opencv" \
"C:\\opencv\\build\\include\\opencv2"
LIBS += -L"C:\\opencv\\build\\x86\\vc10\\lib" \
-lopencv_core242 \
-lopencv_highgui242 \
-lopencv_imgproc242
}
Make sure to replace the 242 number referenced by LIBS with the specific OpenCV version you have.
It's also important to state that OpenCV is compiled with specific flags, and depending on the binary version you installed, sometimes you also need to add the following instructions to the .pro file of your project:
QMAKE_CXXFLAGS_DEBUG += -Zi -MTd
QMAKE_CXXFLAGS_RELEASE += -MT
MTd refers to Multithreaded-Debug-DLL and MT stands for Multithreaded static linking.
Google brought me here when I had the same problem.
The solutions here didn't helped me. But finally I found the problem in my case: I didn't set a value for CMAKE_BUILD_TYPE in cmake gui.
You have the choice between release and debug, and I think you must choose one.
I compiled OpenCV 3.0.0 successfully thanks to that last tip.
karlphillips is correct, there is an error in the way you are linking your opencv dependencies to Qt. You can manually enter the information as indicated by other answers here (every time I did it manually I ended up messing it all up) or you can you use the built in "Add Library..." option (SUPER EASY).
The steps listed below are found in the Qt5 documentation: [http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html][1] under the "To Add Library" section.
Right click on the project file located in the 'project pane' on the left side of the creator... and select "Add Library..."
Follow the instructions of the wizard
Let me add some specificity from here...
Select "External Library"
For the "Library File" navigate to your opencv_worldXXX.lib file (or opencv_worldXXXd.lib file, you will notice that by specifying only one or the other the wizard has a checkbox which includes the other automatically) [ex. ...\opencv\build\x64\vc12\lib\opncv_world.lib]
For the "Include Folder" navigate to the "include" folder within the build. [ex. ...\opencv\build\include]
Select your operating system, dynamic/static library (whichever is appropriate)
Hit NEXT, CLEAN UP, and RUN!
You probably should not use ::cv, just directly use the function and try.
Sorry for the wrong suggestion, the real reason is not able to find your libs:
should use this:
LIBS += E:\\OpenCV\\OpenCV\\opencv\\build\\x86\\vc10\\lib\\opencv_core246.lib

How to avoid console window in Qt application, even after Including "testlib" package (for qWait()) in my .pro file?

Hallo everyone,
I have gone through various threads on this topic but, nothing seems to solve my particular problem. Including testlib, makes the console window appear and there I didnot find any option to suppress this behaviour.
But my application still demands testlib to be present (because i badly wanted to use QTest::qWait() method), and no console window to appear. I tried a few options from the other threads but nothing is working. what should i do to suppress this console window even after using 'testlib"?
The options I tried are
adding CONFIG -= console to my .pro file.
QT += gui \
xml \
core \
testlib
CONFIG += qt \
windows \
uitools \
release
CONFIG -= console
LIBS += extern/ftd2xx.lib
RC_FILE = res/AC-Core.rc
QMAKE_CXXFLAGS += -Wall \
editing the qmake.conf file, the lines
QMAKE_LFLAGS_CONSOLE = -Wl,-subsystem,console, to
QMAKE_LFLAGS_CONSOLE = -Wl,-subsystem,windows
Any other ideas to suppress the appearing of console window are welcome?
Thanks!
You don't have to use QTest to get the functionality of QTest::qWait(). If you look at the source code for qWait() you can see how it works and implement this function yourself:
inline static void qWait(int ms)
{
Q_ASSERT(QCoreApplication::instance());
QTime timer;
timer.start();
do {
QCoreApplication::processEvents(QEventLoop::AllEvents, ms);
QTest::qSleep(10);
} while (timer.elapsed() < ms);
}

compiling maya (3d application ) with qt

including the maya ( 3d application ) classes in qt program gives lot of errors..... i have added all required include paths and libs...the same problem persists ....
this is pro file for my qt project
TARGET = FileCon
TEMPLATE = app
SOURCES += main.cpp \
dialog.cpp
HEADERS += dialog.h \
ConvertFunction.h
FORMS += dialog.ui
LIBS += "C:/Program Files/Autodesk/Maya2008/lib" \
-lOpenMaya.lib \
-lFoundation.lib \
-lOpenMayalib
INCLUDEPATH += "C:/Program Files/Autodesk/Maya2008/include"
DEFINES = _BOOL \
WIN32 \
REQUIRE_IOSTREAM
///////////////////////////////////////////
How is it possible to use maya classes with qt.
Try something like this
LIBS += $$quote(-LC:/Program Files/Autodesk/Maya2008/lib) \
-lOpenMaya \
-lFoundation
qmake LIBS variable
If you are using QtCreator with the included compiler on Windows, it expects ".a" style libraries, rather than Visual Studio ".lib" style libraries.
You still haven't given enough infromation about eaxctly what you are doing. (How are you building, what compiler, etc.) or what is going wrong (exact error messages) to know for sure if that's the issue. But, if my crystal ball is working well today, I'd recommend checking the library format.

Resources