QML doesn't show svg images - qt

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

Related

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

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:
};

Qt creator does not detect opencv

I am trying to run a program in Qt5.6 with openCV3.1, but no matter what I do, it does not detect openCV include.
Projects -> Build Environment -> Include :
I added C:\opencv\opencv3.1.0\opencv\build\include
Projects -> Build Environment -> LIB:
I added C:\opencv\opencv3.1.0\opencv\build\x64\vc14\lib
However, still in the code there is a yellow line indicating that it doesn't detect opencv:
and there are lots of errors like this:
The environment variable for openCV is also set as:
C:\opencv\opencv3.1.0\opencv\build
How should I install Qt with openCV to avoid these problems?
In the .pro file, add the following lines:
INCLUDEPATH += C:\opencv\opencv3.1.0\opencv\build\include
LIBS += -LC:\opencv\opencv3.1.0\opencv\build\x64\vc14\lib \
opencv310.lib \
And also you need to add the .dll file's path C:\opencv\opencv3.1.0\opencv\build\x64\vc14\bin to the system path (this time you need to restart the Qt IDE)

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

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

Can I get qmake -project to add LIBS += .... to my .pro file?

I have a project that uses Qt. So I have "qmake" make my Makefile from the .pro file. But Qmake can also make that .pro file: qmake -project . This worked until I needed to add an external extra library to my project.
I get lots of hits on google that tell me to add LIBS += ... to my project file, but I want to tell qmake -project something that causes it to add it for me. In effect of course I'll be doing it myself, but I don't think that it's proper that I am editing the generated project file.
If for example I add files to the project directory, I'll have to recreate it and add in the library again, or I'll have to manually add the files to the (almost completely computer-generated) project file. I'm now using a script to auto-generate the project file, and then add in the LIBS += directive, but is there a proper way to do this?
When you are developing without the Qt Creator IDE, unless the IDE includes by itself some automatic utilities, you must edit manually the .pro configuration file.
The generated .pro file is a skeleton file which YOU must fill in with the libraries that you need, then the qmake system figures out the other dependencies and compiles your project. It is a essentially a much better version of pkg-config of gtk + Makefiles.
When you add more source and resource files to your project then manually you must add them to the .pro file.
Example:
QT += core gui
TARGET = qtcp1
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
miwidget1.cpp \
lcdrange.cpp
HEADERS += mainwindow.h \
miwidget1.h \
lcdrange.h
FORMS += mainwindow.u
Alternately, you can issue qmake -project over and over again, but this can cause some unforseen accidents, since it includes everything that is in the current directory at the time, including the pre-processed files for conversion to standard C++ from QT dialect. This intermediate files must be erased (cleaned), before the remaking the project and the next make or can lead to tricky problems.
Using the official and free QT Creator IDE takes away most of this burden by adding automatically the new data to the .pro file and cleaning loose ends. Some other IDEs like Code::BLocks and Codelite provide some facilities for QT, but not to the level of QT creator. Some prefer to edit the .pro themselves for custom reasons, other like more other styles of IDEs, like Eclipse.
You should test the waters and decide by yourself what fits best to your needs.
ReEdited, to clarify a few things.

Resources