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
Related
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:
};
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)
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
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.
I have a shared library (with no QT dependency) [library B] that links to another shared library (with no QT dependence as well) [library A].
I am using Qmake and QT Creator 1.3. The problem is that when I build library B and run ldd on the executable, it is being linked to QtCore and QtGui, both of which are pulling in lots of unrequired files, resulting in an executable that is taking long to load, and has unwanted dependencies.
I have tried just about everything to stop qmake from linking these libraries to library B.
A snippet of my project file for library B is shown below:
TEMPLATE = lib
LIBS += -L../datelib/bin -ldatelib_release
QT -= gui core
LIBS -= -lQtGui -lQtCore
CONFIG += dll
CONFIG += debug_and_release
CONFIG(debug, debug|release) {
TARGET =targetnameD
}else {
TARGET = targetname
}
I am using QtCreator 3 on Ubuntu 9.10
QT is version 4.5.2
Put CONFIG -= qt in your .pro file.
You can try with
CONFIG += dll
QT -= gui core
LIBS -= -lQtGui -lQtCore
For apps, you do it like this:
TEMPLATE = app
CONFIG = console
More info here:
qmake common projects
I had similar problem.
What I did was to create new library project with out qtcore and qtgui. Removed all unnecessary files that was created by wizard. Added my files to project folder and modified the *.pro file. It started to work correctly.
It was some problem with QtCreator, it not read correctly .pro file generating .pro.user, witch QtCreator use to build, and wizard generate correct .pro.user file.
I did this with Qt 4.7
Wish this help.
As far as I know, Qt creator doesn't take the .pro configurations into consideration if you don't have them set up separately from the IDE.
You should go to the project's settings, clone the debug configuration, rename it release, set the QMake build configuration to release(!) and change other settings as you see fit. Then you can pick which configuration to build from the IDE.
P.S: Try using Qt Creator 1.3.1 as it fixes a lot of bugs and brings interesting new features.