Why doesn't my Qt application present a GUI when executed? - c++

I have been given a C++/C code with a .pro file to compile in Qt (it is a large, messy code, so I would like to use Qt and the .pro file provided).
The code is intended to generate a GUI. I can compile it in Qt without any errors (on both Mac OS X 10.7.5 and Mac OS X 10.8), and I see the executable. However, when I click on it, nothing happens. When I run it the usual way via the command line nothing happens. Here are the run commands I'm trying:
./calc.app/Contents/MacOS/calc
exec ./calc.app/Contents/MacOS/calc (this one results in the output: [Process completed]).
In the .pro file (below), I do not see anything that seems to indicate I want a GUI. However, I read at the Qt help site that the GUI module does not need to be specified in the .pro file because it is included automatically. Perhaps I am misunderstanding something?
Are the any issues with my .pro file?
TEMPLATE = app
LANGUAGE = C++
TARGET = calc
VERSION = 3.1.0
CONFIG -= qt
CONFIG += warn_on
CONFIG += debug
#CONFIG += windows
CONFIG += console
DEFINES += IPMGEMPLUGIN
DEFINES += NOPARTICLEARRAY
!win32 {
DEFINES += __unix
}
GMS_CPP = ../GMS
GMS_H = $$GMS_CPP
DEPENDPATH +=
DEPENDPATH += .
DEPENDPATH += $$GMS_H
INCLUDEPATH +=
INCLUDEPATH += .
INCLUDEPATH += $$GMS_H
QMAKE_LFLAGS +=
OBJECTS_DIR = obj
SOURCES += main.cpp
include($$GMS_CPP/gms.pri)

I don't know anything about Qt, and of course none of us know anything about the specific application you're compiling - so the assistance I can give you may be woefully inaccurate.
However, this sticks out like a sore thumb:
#CONFIG += windows
CONFIG += console
A quick Google search indicates that Qt does indeed support console applications - that is, applications which do not create a GUI, but instead act as console / terminal / command-line tools. This appears to be the case with the one you're working with. Presuming the application even works, it likely expects input to be passed to it on the command line, and will produce output of some sort in response - but with this configuration, it will not create a GUI.
I recommend contacting the person who gave you this application for further support.

CONFIG -= qt basically means "The target is [not] a Qt application/library and [does not require] the Qt library and header files." You should delete that line. Source: http://qt-project.org/doc/qt-4.8/qmake-variable-reference.html#config
Also, it couldn't hurt to add QT += core gui. This is normally done for you automatically, but since you're having project file problems it couldn't hurt... Also, make sure your main.cpp's main method ends in return a.exec();, and that a is a QApplication instance (Qt 4.x) or a QGUIApplication instance (Qt 5.x). main.cpp should be a short function that creates the main widget or window, shows it, then starts the event loop.
If your project still doesn't work properly, I would highly recommend that you ditch the project file. In other words, I would download the OS X package for the Qt SDK, create a new project, then import your files into the new project. After that, I would pluck only the necessary lines from your old .pro file and put them in the new one until it works (specifically, I noticed you have some custom DEFINES += ...). However, all of this advice assumes the fault lies in the project file, not your code. ;-)

Related

Using preload-file compiler option for emscripten compiler to load local file in Qt

I am building an Qt Application using WebAssembly. I want to open a local file and read it frin my code which isn't exacty easy with WebAssembly. I tried using the preload-file option (reference) in my .pro file:
CONFIG += preload-file /path/to/file/Settings.ini
However, when compiling my application with WebAssembly, It fails showing my the following error:
Application exit (RuntimeError: Aborted(native code called abort()))
I am currently using Qt 6 with the fitting Emscripten version. My code works when compiling with GCC. Of course, emscripten compiles when removing the file handling stuff from my code. Using a file dialog isn't a suitable option.
I noticed you are using CONFIG += but the emscripten reference says it is a linker flag. Try using instead QMAKE_LFLAGS += --preload-file /path/to/file/Settings.ini.
Personally, I have not tested preload-file option but two other options have been working for me:
The similar embed-file functionality. In the .pro file add QMAKE_LFLAGS += --embed-file ../../cdpcore/Templates/Models#Models to make the folder specified to be available in [working directory]/Models.
Use the Qt Resource system to embed files. Basically add a .qrc file to your project that lists resources to embed into the binary and then into the .pro file add RESOURCES += resources.qrc.

MATLAB Engine in Qt C++ Specified Module Could Not be Found

Using MATLAB 2018a or newer, integrating with Qt 5.15.2. Tried the instructions here:
https://www.mathworks.com/help/matlab/matlab_external/build-c-engine-programs.html
So my .pro file looks as follows:
# MATLAB Engine Includes
LIBS += -LC:\Progra~1\MATLAB\R2018a\extern\lib\win64\mingw64 -llibMatlabEngine
LIBS += -LC:\Progra~1\MATLAB\R2018a\extern\lib\win64\mingw64 -llibMatlabDataArray
INCLUDEPATH += C:\Progra~1\MATLAB\R2018a\extern\include
DEPENDPATH += C:\Progra~1\MATLAB\R2018a\extern\include
Then some of my code looks as follows:
std::unique_ptr<matlab::engine::MATLABEngine> matlabPtr;
// Instantiate interface to MATLAB
std::vector<std::u16string> matlabInstances;
matlabInstances = matlab::engine::findMATLAB(); // find any existing MATLAB instances
if (!matlabInstances.empty()) { // if we have one, connect to it
matlabPtr = matlab::engine::connectMATLAB(matlabInstances[0]);
} else { // if we don't have one, create a new one*/
matlabPtr = matlab::engine::startMATLAB();
}
When I go to run this, I get an error message in Qt Application Output that says:
The specified module could not be found.
I commented out individual lines and found that even if I comment out the call to findMATLAB(), the same error occurs at the first call using the matlab::engine namespace.
I thought this was maybe a similar issue to Qt where you have to either statically link the libraries or copy the dlls into the local run folder, so I copied the dll files from the C:\Program Files\MATLAB\R2018a\extern\bin\win64 into the debug folder and had no additional luck.
Is this a dependency issue? How do I figure out which module is unfindable? Does anyone have a more complete list of steps required to get MATLAB integrated with 2018a MATLAB or later? I found many results for older versions of MATLAB, but they had different header files and folder structures that don't seem to match. Thanks in advance!
I found a solution...if I add the MATLAB path to C:\Progra~1\MATLAB\R2018a\extern\bin\win64 to my PATH variable, it works as expected, so I just need to organize the .dll files to be on the PATH. Would be interested in information on why I couldn't copy the dlls to my local directory to make them work.

'fbxsdk.h' file not found in my Mac Qt project,How add FBX SDK in my Mac Qt project?

I developed a Qt project on Mac which transplanted from Windows Qt,everything is working fine in Windows Qt,but in Mac Qt show many errors, one of them is :
'fbxsdk.h' file not found
it seem to say I have not add FBX SDK to my Mac Qt project. so I add it according official website: https://help.autodesk.com/view/FBX/2017/ENU/?guid=__files_GUID_724E9FAD_AFA0_4348_BDAA_6CF2FDF2FF55_htm .
and study add FBX SDK in Windows Qt project in this website : https://forums.autodesk.com/t5/fbx-forum/including-sdk-to-qt-creator/td-p/8184654 .
so I edit my .pro, the content is here :
LIBS += /Applications/Autodesk/FBX\ SDK/2019.2/lib/clang/debug/libfbxsdk.a
LIBS += /Applications/Autodesk/FBX\ SDK/2019.2/lib/clang/debug/libfbxsdk.dylib
INCLUDEPATH += /Applications/Autodesk/FBX\ SDK/2019.2/include
DEPENDPATH += /Applications/Autodesk/FBX\ SDK/2019.2/lib/clang
it still show error : 'fbxsdk.h' file not found, how should I add FBX\ SDK in my Mac Qt project,thanks a lot!
I had fixed it:
I used the 'otool -L' with execute file of my App in the terminal,it shows the libfbxsdk.dylib load path is '#executable_path/libfbxsdk.dylib',in my '#executable_path/' there no libfbxsdk.dylib in it,so it shows error,so I think why the loadpath of 'libfbxsdk.dylib' is '#executable_path/libfbxsdk.dylib',can I change it?
the answer is 'YES'
how I change the 'install name' of libfbxsdk.dylib you can find in this pic :
of course,you can use a another popular way,change the loadpath of 'libfbxsdk.dylib' use the 'install_name_tool -change' in the terminal,here is my example to change it in pic:
now you use the 'otool -L' with execute file in the terminal again,the loadpath of libfbxsdk.dylib change to '/Applications/Autodesk/FBXSDK/2019.2/lib/clang/debug/libfbxsdk.dylib' from '#executable_path/libfbxsdk.dylib'

How to link opencv in QtCreator and use Qt library

This question must be duplicate many times, but it just doesn't work and sometimes it still remains unanswered. Sources of information are mainly these
http://www.laganiere.name/opencvCookbook/chap1s1_2.shtml
http://www.youtube.com/watch?v=dgcXYQijV6c
This is the summation of what I think one should/can do. (And now it works for me.) Hopefully I mentioned everything from the very beginning, the aim is to write a very clear tutorial.
Installation of OpenCV for QtCreator
I have already MS Visual Studio 2010 Professional installed. (I have a free licence as a student) - I think this is not necessary, just a mention
Download: Qt 5.0.1 for Windows 32-bit (MinGW 4.7, 823 MB)
2.1 Install: Warning, everything that Qt uses (e.g. OpenCV) must be in directories that don't contain white-spaces in their names. - i.e. "Program Files" is wrong. (But I don't want different program files to accumulate directly on C, so I've only made a folder "Programs" in which everything important is installed)
Download: cmake-2.8.10.2-win32-x86.exe - Install for all users (this can be in Program Files)
Download: OpenCV-2.4.0.exe, extract to: C:\Programs\opencv24 - it'll create a dir "opencv"; add another folder "opencv_bin". Now it looks like this:
C:\Programs\opencv24\opencv*
C:\Programs\opencv24\opencv_bin
Set PATH environment variable, so that there be a link to MinGW compiler. e.g. C:\Programs\Qt\Qt5.0.1\Tools\MinGW\bin;
Start cmake-gui.exe
6.1 source code: set the default dir for OpenCV; C:\Programs\opencv24\opencv
6.2 binaries: set the opencv_bin dir; C:\Programs\copencv24\opencv_bin
6.3 click configure:
Choose MinGW Makefiles and Specify native compilers, click next
Field C is for gcc.exe; C:/Programs/Qt/Qt5.0.1/Tools/MinGW/bin/gcc.exe
Field C++ is for g++.exe; C:/Programs/Qt/Qt5.0.1/Tools/MinGW/bin/g++.exe
Field fortran can be empty, click finish
6.4 Many red lines will appear To the search field enter one by one: WITH_QT, WITH_TBB, WITH_IPP, WITH_CUDA, CMAKE_BUILD_TYPE
WITH_QT - must be selected.
WITH_TBB, WITH_IPP, WITH_CUDA - must be unselected
CMAKE_BUILD_TYPE - click and enter a text "Debug" (without quotes).
Clear the text from the Search field.
6.5 click configure and keep clicking configure until all red lines are gone, then click generate and close cmake-gui.exe
Go to the terminal (~command prompt), cd to the directory where are the builds (opencv_bin) and type mingw32-make
When the process ends after a long time, type mingw32-make install
Add into Path variable the path to the QtCreator/bin C:\Programs\Qt\Qt5.0.1\Tools\QtCreator\bin
Now I have created a new console app in QtCreator.
//cvHello.pro
QT += core
QT -= gui
TARGET = cvHello
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
INCLUDEPATH += C:/Programs/opencv24/opencv_bin2/install/include
LIBS += "C:/Programs/opencv24/opencv_bin2/bin/*.dll"
SOURCES += main.cpp
OTHER_FILES += \
img.JPG
And the main file:
//main.cpp
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv/cv.h"
using namespace std;
int main()
{
cout << "Hello World!" << endl;
cv::Mat mat;
mat = cv::imread("img.JPG");
cvNamedWindow("hello");
cv::imshow("hello",mat);
cvWaitKey(0);
return 0;
}
Finally I am starting to be happy. When adjusting this question I had to try all the ways how to define LIBS. Listing them manually helped, at first I wrote them somehow wrong.
This is how it works finally:
LIBS += -LC:\\Programs\\opencv24\\opencv_bin2\\bin \
libopencv_core240d \
libopencv_highgui240d \
libopencv_imgproc240d \
libopencv_features2d240d \
libopencv_calib3d240d \
The originally accepted answer did not work for me, I am running MSVC2013 Professional and QT5.9. I found SIMPLE and SUREFIRE CROSS-PLATFORM solution that should help anyone who is trying to link an external library (like openCV) with QT.
The steps listed below are found in the Qt5 documentation: http://doc.qt.io/qtcreator/creator-project-qmake-libraries.html 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_world310.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!

how open in eclipse ".pro File Editor"

i'm need in eclipse the qt and openCV library. i'm found the tutorial http://www.welding.iat.uni-bremen.de/cms/index.php?view=article&catid=14%3Aimage-processing&id=14%3Aa-tutorial-on-integrating-eclipse-qt-and-opencv&format=pdf&option=com_content&Itemid=24 where writen last step "
We make sure that the Advance Mode is selected, we create a New Variable (1) and we give the name LIBS to this variable (2)
selecting the Append as Assignment Operator.
We have to add the following content to the variable(2), -L/usr/local/lib -lcxcore -lcv -lhighgui -lcvaux".
how my open last window so as double clicking don't open. Opens file where code
TEMPLATE = app
TARGET = ex1
QT += core gui
HEADERS += ex1.h
SOURCES += main.cpp \
ex1.cpp
FORMS += ex1.ui
RESOURCES +=
how my run it task?
sorry bad english.
If I understand correctly: Right click on .pro file and go to 'Qt Project Editor', if it is not there then you can use the text editor option (or something is wrong with your Eclipse Qt installation).