openCV in Qt Creator on Mac - c++

I am new to C++ so this is probably a simple fix, but I have not been able to run my program even after reading Stack Overflow's many posts regarding openCV and Qt creator. This is now my 4th day trying to get openCV working in Qt creator, so any help would be greatly appreciated!
I know openCV is installed and working on my computer because I am able to build and run programs using it by running g++ pkg-config --libs --cflags opencv -o name name.cpp in terminal, just as long as I don't try to use openCV in Qt creator. I installed openCV through Homebrew and downloaded Qt creator from its website. I also have qt installed by running "brew install qt" in terminal.
I tried linking openCV to my Qt project by editing the project file which now reads:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = opencvTestQT2
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
QT_CONFIG -= no-pkg-config
CONFIG += link_pkgconfig
PKGCONFIG += opencv
But upon trying to run it I get the error:
opencv development package not found
I have also tried adding to my project file lines such as:
INCLUDEPATH += /usr/local/Cellar/opencv/2.4.11_1/include/
QMAKE_MACOSX_DEPLOYMENT_TARGET = 10.10
LIBS += -L/usr/local/Cellar/opencv/2.4.11_1/lib -lopencv_imgcodecs -lopencv_highgui
but none of them allow my program to be built.
I am using a Mac running version 10.10.4, openCV 2.4, and Qt Creator 3.4.2 in case that helps.
Thanks in advance

Click on projects on the left pane -> Build & Run -> on Build Environment, add Path to /usr/local/bin in order for qt creator to find the pkg-config.

as Dae Choi said, the pkg-config is not found. Doing that procedure will work. Just remember to update the run as well.
This error will show:
Starting /Users/sgb/build-imagenes-Desktop_Qt_5_9_1_clang_64bit-
Debug/NBasic.app/Contents/MacOS/NBasic...
dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from:
/System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /usr/local/lib/libJPEG.dylib
in /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO
The program has unexpectedly finished.
Just update in Projects -> Build & Run -> Run -> DYLD_LIBRARY_PATH to unset. Save and compile again. There are other thread where you can check as well.
Qt application throws “dyld: Symbol not found: __cg_jpeg_resync_to_restart”

Related

Entry point not found on OpenCV dll with Qt 5.12

TLDR: Linking OpenCV with QT MingW makes application crash in Debug but not release.
I am trying to use OpenCV in a large multi OS project based on Qt. I have easily managed to build OpenCV for Mac and Linux but I am very much struggling to use it on Windows.
Environment:
Qt 5.12.2 MinGW
MinGW 8.1.0 64bit
OpenCV basically all versions since 4.1.0
CMake 3.19
What I tried
I first tried to build OpenCV from source following his link https://wiki.qt.io/How_to_setup_Qt_and_openCV_on_Windows but had some issues running the application in Debug such as Entry Point not Found in opencv Library (exact error below)
I lately used prebuilt packages from MSys2 using its pacman and tried version 4.2 to 4.5 without real success. I managed a couple of time to link the OpenCV libraries from the installation path of msys (C:\msys64\mingw64\bin) and with this path in the environment PATH I was able to launch the application using the .exe generated by Qt. However once I dragged the needed libraries into our third party libraries folder for deployment the application can't start anymore in Debug (with Qt nor with the .exe).
I tried in Release mode and everything works fine
Now everytime I run the application in Debug with Qt the program crash immediately without even entering the main. I have the following error when I use the .exe:
I have seen that it could be a TBB issue so I tried using a different version from MSys without success.
I tried to change the PATH variables from Qt for the Build and the Run without success.
My includes and Libs in my .pri are used as follow (they are all found during the build)
INCLUDEPATH += -I $$PWD/../../ext/OpenCV/include/opencv4
DEPENDPATH += -$$PWD/../../ext/OpenCV/include/opencv4
LIBS += -L$$PWD/../../ext/OpenCV/lib/$$OSFOLDER/$$ARCHFOLDER -lopencv_imgproc430
LIBS += -L$$PWD/../../ext/OpenCV/lib/$$OSFOLDER/$$ARCHFOLDER -lopencv_core430
LIBS += -L$$PWD/../../ext/OpenCV/lib/$$OSFOLDER/$$ARCHFOLDER -lopencv_dnn430
LIBS += -L$$PWD/../../ext/OpenCV/lib/$$OSFOLDER/$$ARCHFOLDER -lopencv_imgcodecs430
LIBS += -L$$PWD/../../ext/OpenCV/lib/$$OSFOLDER/$$ARCHFOLDER -lopencv_highgui430
Okay so I finally managed to get it work!
As I said in my question this error happens sometimes when the TBB version is not correct so here's what I did:
Build manually TBB with this repository: https://github.com/wjakob/tbb which contains a CMake-based build system of the official repository : https://github.com/oneapi-src/oneTBB
Build OpenCV with the version needed using the compilers you will use later in your application:
Uncheck 'BUILD_TBB', check 'WITH_TBB' and point to the previously built TBB libraries and include.
Add the flags you need ( OPENCV_ENABLE_ALLOCATOR_STATS=OFF for instance ) and build it.
Finally add the libraries from 'path/to/opencv-build/bin' instead of 'path/to/opencv-build/install/bin' (maybe that's what we should always do but I wasn't sure) and it worked for me!

Build boost with qt app running on ios

I am working on a qt app which runs on am ios device. I am building the app on a Mac OSX laptop. It uses C++ for most part of it. I need to build the app with boost C++ library to use boost asio. So following are the steps I did:
1. Install boost on my mac laptop using port install boost. This puts boost headers into /opt/local/include & boost libs into /opt/local/lib as I see.
2.Next, I used the following lines in my qt app`s .pro file to build
INCLUDEPATH += /opt/local/include
LIBS += -L/opt/local/lib
LIBS += -lboost_system-mt -lboost_thread-mt
Then, I build it. It says "symbols not found for architecture arm64" & "linker command failed with exit code 1"
Can anyone please point out what is the correct way to build boost for a qt app running on ios ?
To use boost on iOS, you need a "cross-compiled" version, for the iPhone's processor architecture. The version you installed locally on your Mac was compiled for architecture x86_64. For an iOS app you need armv7 and arm64.
Fortunately, there seems to be a precompiled boost library for iOS available under https://github.com/danoli3/ofxiOSBoost, which looks like it's exactly what you need. Maybe you can have a look at that.

QT File menu not integrating into title bar

I am writing a basic gui application in QT creator 3.5.1 and I am using QT 5.5. I have downloaded QT/QT creator via their website. I am currently running Ubuntu 15.04 64 bit.
I am running into an issue regarding the integration of the menu bar into the title bar. The issue being that no integration is happening (the menu bar isn't appearing in the title bar) . The menu bar appears where it would have in the past, below the tile bar. Here is an image of what is happening:
How can I go about resolving this issue?
UPDATE:
I installed qt 5.4.1 via apt-get, and qt creator. When I compile against this, my title bar integration works! So the question is, what is different? The people I am developing with are using QT 5.5.1, and I would like to use the same version as them. Is there something I can do differently this time around?
The unique way that i found was in this blog. He claims that this method works on Qt Creator, but i've tested on Ubuntu 32/64 bits Qt5 apps (developed by me) and it seems to works fine too!
The steps are:
Open terminal
Enter sudo apt-get install libgtk2.0-dev libdbusmenu-qt5-dev
Set current directory with CD command (the appmenu project will live here)
Enter command apt-get source appmenu-qt5
Now, the blog still using command line but the next steps can be done by opening the project in Qt Creator (the project is on the current directory).
Using some text editor (can be Qt Creator of course), edit the following lines of appmenu/src/src.pro:
CONFIG += X11 link_pkgconfig debug
PKGCONFIG += dbusmenu-qt5 gtk+-2.0
DESTDIR = ./
to (if you want a dynamic library):
CONFIG += X11 link_pkgconfig
PKGCONFIG += dbusmenu-qt5 gtk+-2.0
or (if you want a statically linked library):
CONFIG += X11 link_pkgconfig static
PKGCONFIG += dbusmenu-qt5 gtk+-2.0
Open the project with Qt Creator (if you haven't done already) select the mode of build (Release mode seems to be smaller in size) and build.
If built succesfully (as a dynamic library), you will have inside your Qt5 installation folder /plugins/platformthemes a plugin called libappmenu-qt5.so. To get menu integration, just place the lib in a platformthemes subfolder of your target app (including Qt Creator).
Or if built succesfully (as a statically linked library), you will have inside your Qt5 installation folder /plugins/platformthemes a file libappmenu-qt5.a. This is the static library. To integrate it with your app, add to your project file:
QT += core-private gui-private platformsupport-private dbus widgets
LIBS += $$[QT_INSTALL_DATA]/plugins/platformthemes/libappmenu-qt5.a
CONFIG += X11 link_pkgconfig
PKGCONFIG += dbusmenu-qt5 gtk+-2.0
And to your main.cpp:
#include <QtPlugin>
Q_IMPORT_PLUGIN(AppMenuPlatformThemePlugin)
int main(int argc, char *argv[])
...
And this should be the result:
Edit (valid when building as dynamic library): Note that you wouldn't need to recompile your Qt apps nor Qt Creator .
For Qt Creator you need to place libappmenu-qt5.so in your Qt Installation folder: /Tools/QtCreator/lib/Qt/plugins/platformthemes
If you want to redistribute your Qt application, just share inside the folder of your executable the folder platformthemes with libappmenu-qt5.so inside it. Like any other Qt plugin.
Edit 2: Is also possible to build a statically linked plugin, if you don't want extra dependencies.
You can try to set "nativeMenuBar" property of QMenuBar Object is false.
Because this property has the default value is true.

collect2:error in Qt

I just installed Qt and I created a console project and printed hello world and it printed that out perfectly. I also added opencv libraries to the same project and was able to load an image successfully. Then i created a new project as qt widget application project and without making any changes to the project (which comes with the main window class and main source file) I run it the following error pops up.
error: cannot find -lGL
error: collect2: error: ld returned 1 exit status
what do I do?
my .pro file
#-------------------------------------------------
#
# Project created by QtCreator 2015-03-15T17:46:46
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = untitled
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
I was able to fix this. Apparently it depends upon the libgl1-mesa-dev package. So install the package and restart Qt . I have ubuntu 14.04.02 and it showed some errors when I tried installing in the conventional way
sudo apt-get install libgl1-mesa-dev
So I tried
sudo aptitude install libgl1-mesa-dev
That didn't work well either. A different website showed a way around it
sudo apt-get install xserver-xorg-dev-lts-utopic mesa-common-dev-lts-utopic libxatracker-dev-lts-utopic libopenvg1-mesa-dev-lts-utopic libgles2-mesa-dev-lts-utopic libgles1-mesa-dev-lts-utopic libgl1-mesa-dev-lts-utopic libgbm-dev-lts-utopic libegl1-mesa-dev-lts-utopic
This installed properly. Now when I restarted Qt it worked properly.
for your reference:
http://xrong.org/notes/install-Qt-OpenCV-Ubuntu
http://answers.ros.org/question/203610/ubuntu-14042-unmet-dependencies/

qwt build - qmake build (Qt 5.3)

I want to compile the qwt library using qt 5.3. Previously I had older versions of Qt. So, when I call the Qt 5.3.0 32-bit for Desktop (MSVC 2012 OpenGL) shell and move to the directory, which contains qwt (C:\qwt-6.1.0), then perform qmake qwt.pro I get this error:
Cannot read c:/Qt/Qt5.0.2/mkspecs/win32-msvc2010/qmake.conf: The system cannot find
the path specified. Could not read qmake configuration
file c:/Qt/Qt5.0.2/mkspecs/win32-msvc2010/qmake.conf.
Error processing project file: C:\qwt-6.1.0\qwt.pro
Calling:
qmake -set QMAKESPEC "C:\Qt_5.3\5.3\msvc2012_opengl\mkspecs\win32-msvc2012\"
Does not help.
PS. Solution is found! I've tried not to do like is in qwt tutorial, simple open *.pro file by Qt Creator. After this just "build" and everything was done. Without console