QT Creator exits with code 0 when running program - qt

I am trying to run a simple OpenCV program in QT Creator 2.3, QT 4.7.4. I know the syntax is correct, but my program does not get run. When I run it, I simply get the qtcreator_process_stub.exe window with "Press <RETURN> to close this window...".
Why is this? My .pro file looks as such:
QT += core
QT -= gui
TARGET = myQtConsoleProject
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\\opencv\\release\\include
LIBS += -LC:\\opencv\\release\\lib \
-lopencv_core231.dll \
-lopencv_highgui231.dll \
-lopencv_imgproc231.dll \
-lopencv_features2d231.dll \
-lopencv_calib3d231.dll
The application output is
Starting C:\Users\chris\QT\myQtConsoleProject-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Release\release\myQtConsoleProject.exe...
C:\Users\chris\QT\myQtConsoleProject-build-desktop-Qt_4_7_4_for_Desktop_-_MinGW_4_4__Qt_SDK__Release
\release\myQtConsoleProject.exe exited with code 0
The contents of my source code is as follows:
#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
int main() {
printf("not outputting...\n");
cv::Mat image= cv::imread("C:/temp/img.jpg");
cv::namedWindow("My Image");
cv::imshow("My Image", image);
cv::waitKey(50000);
return 1;
}
I've added C:\opencv\release\bin to my path.

The fact that your console window does not show any lines except the "Press to close" line means that your application does not output anything to the console.
I see you have a console project configured, meaning it has no GUI. But due to the fact that your program compiles fine this might not be a problem.
Can you post the code of your main() function? The behavior you describe seems to be related to your code, not the project configuration.

Related

Configuration of GNU Radio and UHD project with Qt Creator

I'm currently implementing a GUI interface for a very small GNU Radio application. The application will simply connect to a USRP device, receive some IQ samples and forward them through a TCP socket. Following the gqrx project file example, I was able to run some example gnuradio blocks (the dial tone example from gr-analog). Problems started when I tried to include UHD/USRP blocks into the project. Basically, Qt creator report the following error:
/usr/local/lib/libgnuradio-uhd.so:-1: error: undefined reference to `uhd::usrp::multi_usrp::ALL_MBOARDS
The .pro file configured as shown below:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = USRPDialog
TEMPLATE = app
SOURCES += main.cpp \
usrpdialog.cpp
HEADERS += \
usrpdialog.h \
ui_sdrdialog.h
FORMS += \
sdrdialog.ui
CONFIG += c++11
CONFIG += link_pkgconfig
PKGCONFIG += gnuradio-analog \
gnuradio-blocks \
gnuradio-digital \
gnuradio-filter \
gnuradio-fft \
gnuradio-runtime\
gnuradio-uhd
LIBS += -lboost_system$$BOOST_SUFFIX -lboost_program_options$$BOOST_SUFFIX -lboost_thread$$BOOST_SUFFIX
LIBS += -luhd -lgnuradio-uhd
And this is the function that calls the uhd::usrp_source object
void USRPDialog::createFlowgraph()
{
tb = gr::make_top_block("usrp");
d_tcpSource = gr::blocks::tcp_server_sink::make(sizeof(gr_complex),"127.0.0.1",d_rxTCPPort,true);
d_usrpSource = gr::uhd::usrp_source::make(uhd::device_addr_t(ipAddressLineEdit->text().toStdString()),
uhd::stream_args_t("fc32"));
//Connecting blocks
tb->connect(d_usrpSource,0,d_tcpSource,0);
tb->start();
}
UHD is installed in my system (GNU Radio flowgraphs in my system can connect to USRP devices without any problem). Could anyone shed some light as to why this problem occurs?
Thanks in advance.
too late answer , but fo future ...
I recommend you that use this page step by step: Build UHD from sources
and after these steps , you can use all methods classes and uhd API to build your project in C/C++.
note:don't forget installing winusb for detect usrp devices.
you can use examples in dir: uhd/host/examples.
you can use simple example for finding (detecting usrp device) by name: uhd_find_devices.exe after building uhd , etc.

moc failing with 'Undefined interface' with Qt 5.10 in a Docker container

A very simple Qt project fails to build for me with Qt 5.10 in a Docker container (with an image derived from opensuse:tumbleweed). The project is as follows:
sh-4.4# cat test.pro
TEMPLATE = app
TARGET = test
INCLUDEPATH += .
INCLUDEPATH += sub
HEADERS = obj.h sub/iface.h
SOURCES = obj.cpp main.cpp
sh-4.4# cat sub/iface.h
#pragma once
#include <QtPlugin>
class Interface
{
public:
virtual ~Interface () {}
};
Q_DECLARE_INTERFACE (Interface, "org.meh.interface/1.0")
sh-4.4# cat obj.h
#pragma once
#include <QObject>
#include <sub/iface.h>
class Obj : public QObject
{
Q_OBJECT
Q_INTERFACES (Interface)
};
sh-4.4# cat obj.cpp
#include "obj.h"
sh-4.4# cat main.cpp
int main() {}
In this case moc complains as follows:
obj.h:9: Error: Undefined interface
Everything is fine in another container with Qt 5.9, and everything is also fine with Qt 5.10 when the project is built in openSUSE Build Service (which uses something else instead of Docker). Some quick googling did not reveal any relevant bugreports for recent Qt versions.
What could be wrong?
Running moc under strace shows Operation not permitted on various statx calls, which sheds some light on why exactly it fails (also, related to this question). This pull request is hopefully going to fix this.
Did you try to run the container with the --privileged (see Which capabilities are needed for statx to stop giving EPERM)?

boost compute (opencl wrapper), initial setup problems (qt, g++)

Been trying to compile this sample code: https://github.com/boostorg/compute/blob/master/README.md
I installed QT Creator 5.7 using mingw530
I compiled the boost libraries using
bootstrap.bat gcc
b2 install --prefix="C:\Boostbuild" --toolset=gcc
bjam --build-dir=c:/Dev/Boost/Boost_lib toolset=gcc stage
I installed AMD SDK 3.0, 2.9.1, and 2.9
I even downloaded opencl 1.1, 1.2, and 2.1 cl.hpp and tried to include that.
The compile starts, but I get a slew of errors
C:\Dev\Boost\compute-master\include\boost\compute\device.hpp:80: error: undefined reference to `clRetainDevice#4'
C:\Users\User\Documents\Projects\build-console-test-Desktop_Qt_5_7_0_MinGW_32bit-Debug\debug\main.o:-1: In function `ZN5boost7compute6deviceaSERKS1_':
I tried a simple qt console app, using the code supplied by boost compute
Note: this isn't specific to qt, I've also tried compiling this using
g++ -I/path/to/compute/include sort.cpp -lOpenCL
doing an -I to each of the include's in the main.cpp (see below)
Ideally, I'd like to know how to compile the example given on their page, with includes and all (and relevant amd sdk and/or opencl versions) along with the necessary included libraries.
My qt project file libraries
INCLUDEPATH += C:\Dev\Boost\compute-master\include
INCLUDEPATH += C:/Users/User/Downloads/dev/boost_1_61_0
INCLUDEPATH += "C:\Program Files (x86)\AMD APP SDK\2.9-1\include"
My main.cpp
#include <iostream>
#include <vector>
#include <algorithm>
#include <boost/compute.hpp>
//#define CL_USE_DEPRECATED_OPENCL_1_1_APIS
//#undef CL_VERSION_1_2
//#include <C:\Dev\OpenCL\2.1\cl.hpp>
namespace compute = boost::compute;
int main()
{
// get the default compute device
compute::device gpu = compute::system::default_device();
// create a compute context and command queue
compute::context ctx(gpu);
compute::command_queue queue(ctx, gpu);
// generate random numbers on the host
std::vector<float> host_vector(1000000);
std::generate(host_vector.begin(), host_vector.end(), rand);
// create vector on the device
compute::vector<float> device_vector(1000000, ctx);
// copy data to the device
compute::copy(
host_vector.begin(), host_vector.end(), device_vector.begin(), queue
);
// sort data on the device
compute::sort(
device_vector.begin(), device_vector.end(), queue
);
// copy data back to the host
compute::copy(
device_vector.begin(), device_vector.end(), host_vector.begin(), queue
);
return 0;
}
if I uncomment out the include cl.hpp, I get further
C:/Dev/Boost/compute-master/include/boost/compute/allocator/buffer_allocator.hpp:91: undefined reference to `clReleaseMemObject#4'
The "slew of errors" are link errors because the location of the AMP APP SDK libraries (libOpenCL.a in this case) is missing.
E.g. to link to the 32 bit version for MinGw, -lOpenCL becomes:
-L"C:\Program Files (x86)\AMD APP SDK\2.9-1\lib\x86" -lOpenCL
Or you could add the following to your qt .pro file:
# Ensure that the AMDAPPSDKROOT environment variable has been set
OPENCL_ROOT = $$(AMDAPPSDKROOT)
isEmpty(OPENCL_ROOT) {
error("Please set AMDAPPSDKROOT to the location of the AMD APP SDK")
} else {
message(Using Boost from: $$OPENCL_ROOT)
}
INCLUDEPATH += $$OPENCL_ROOT/include
LIBS += -L$${OPENCL_ROOT}/lib/x86
LIBS += -lOpenCL
Note: the AMDAPPSDKROOT environment variable is normally created when you install the AMD APP SDK. In your case it should be set to:
C:\Program Files (x86)\AMD APP SDK\2.9-1\

Qt and using an existing win32 dll

I want to do some development work using Qt. I have built several small apps and followed
some tutorials. All's fine and seems straight forward.
The development to be done involves using existing code that is contained in win32 dlls. I want to reuse this code with minimum fuss and link them into my Qt app. I have the headers, libs and the dlls so I'll be linking at compile time not dynamically at runtime.
I have tried to do this but Qt always complains always complains with link errors similar to:
main.obj:-1: error: LNK2019: unresolved external symbol _imp_Add referenced in function _main
No matter how I tweak the .pro file it always complains.
I've spent many hours googling and found snippets of info. I could not find one answer that told the whole story. What I'm after is a set of steps, a tutorial like sequence that needs to be followed. There may even be an example in the Qt installation examples but I've been unable to find it.
Here is the simple 'knock-up' I've been trying to get to work in order to move on to the main development. It's based on the MS tutorial dll MathsFunc.
The win32 dll:
// Visual Studio 2005
//Funcs.h
#ifdef MATHFUNCS_EXPORTS
#define MATHFUNCSDLL_API __declspec(dllexport)
#else
#define MATHFUNCSDLL_API __declspec(dllimport)
#endif
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif
// Returns a + b
MATHFUNCSDLL_API double Add(double a, double b);
#ifdef __cplusplus
} /* Assume C declarations for C++ */
#endif
//Funcs.cpp
#include "Funcs.h"
double Add(double a, double b)
{
return a + b;
}
The Qt app that imports the dll.
//main.cpp
#include <QCoreApplication>
#include "../../mathfuncs/funcs.h"
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
double dResult = Add(1.0,2.0);
printf("1 + 2 = %f\n",dResult);
return a.exec();
}
//The Qt project file .por
#-------------------------------------------------
#
# Project created by QtCreator 2013-03-04T09:16:18
#
#-------------------------------------------------
QT += core
QT -= gui
TARGET = Useit
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += c:/tmp/mathfuncs
HEADERS += c:/tmp/mathfuncs
LIBS += c:/tmp/mathfuncs/MathFuncs.lib
Thanks in advance for any input.
D.

Non Qt console app in Qt Creator

I want to create the simple console app below in Qt Creator:
#include <iostream>
int main(int argc, char* argv[])
{
std::cout << "Hello WOrld";
return 0;
}
I've seen some possible duplicates on SO, I have ticked the "Run in Terminal" option in Run Settings. A console window does pop up on CTRL+R, but it does not display "Hello World", simply "Press Enter to exit".
The above is by creating an Empty Project.
I have tried creating a "Qt Console Application" which generates the code below. This does work fine, but I want the simple non Qt version above.
#include <QtCore/QCoreApplication>
#include <iostream>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
std::cout << "Hello World";
return a.exec();
}
Besides ticking "Run in Terminal" you need to add "CONFIG += console" to your .pro file (if you are using qmake).
TEMPLATE = app
CONFIG += console
SOURCES += main.cpp
After trying Qt again after a long time, it now works. The project file has "CONFIG -=qt" by default. I'm not sure if this alone would have solved the problem back then, but it is the only difference I can see.
Full .pro file:
TEMPLATE = app
CONFIG += console
CONFIG -= qt
SOURCES += main.cpp
The only fault I can see with that example is that the stream is not flushed (please change the std::cout line to:
std::cout << "Hello World" << std::endl;
However, that is unlikely to be the issue you have, although the following example that I've found at http://www.richelbilderbeek.nl/CppQtHelloWorldConsole.htm implies that it is indeed a buffer handling issue where QtCreator makes some assumptions regarding buffering. (Note that that url adds a std::cin.get() call, which forces the application to pause, and thus, you should certainly see some output).
If you stumbled over this thread, because your application instantly exits and the console just shows "Press enter to exit":
This is how your application behaves, if you launch it from QtCreator and it can't find dependent DLLs (very unhelpful, by the way). To find out what exactly is missing, you can start your application without QtCreator. Dependent DLLs have to be in one of the locations listed here http://msdn.microsoft.com/de-de/library/7d83bc18.aspx.

Resources