# Opencv sample in Qt crashes immediately with the error 'The program has unexpectedly finished'

I tried to create a simple Opencv application in Qt and upon running, the whole application is crashed. If I comment out the opencv related codes from the project, the project runs just fine.
What I did :

Downloaded the Qt 5.5.0 VS2013 64bit version


There were already prebuilt binaries in when I extracted the Opencv package, But all tutorials on the net wanted me to recompile the source codes so did I.
the package contains :

build
sources


created a new folder named mymade to hold the binaries next to the other two directories.
so it now looks like this :

 build
sources


Steps: Fired up CMake, specified the source folder from the extracted files and specified mymade as the output for binaries.
checked all options that had a opencv in their names, plus Qt! and configured it and subsequently generated the files.
This is the resulting contents :

So all is done and I now need to build the binaries. I opened OpenCV.sln and compiled the release and debug binaries .
the dlls are placed inside bin directory, and the lib files are placed inside lib folder .
Now its the time to configure the Qt projects .pro file So I used the header files from build directory, and for libs I used the lib folder from mymade folder. This is the first configuration that I came up with, which compiles without any linker issues, but crashes just immediately.
the initial changes in project file :

#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = OpenCVTest
TEMPLATE = app

SOURCES += main.cpp\
mainwindow.cpp

INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include

FORMS    += mainwindow.ui


doing this in project file as it was suggested by answers like this didnt do any good either :

#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = OpenCVTest
TEMPLATE = app

SOURCES += main.cpp\
mainwindow.cpp

INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include

FORMS    += mainwindow.ui


this fails as well :

#-------------------------------------------------
#
# Project created by QtCreator 2015-10-06T14:04:20
#
#-------------------------------------------------

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = OpenCVTest
TEMPLATE = app

SOURCES += main.cpp\
mainwindow.cpp

INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include

LIBS += -lopencv_core300 -lopencv_highgui300 -lopencv_imgcodecs300 -lopencv_ml300 -lopencv_objdetect300 -lopencv_photo300 -lopencv_hal300 -lopencv_shape300 -lopencv_flann300 -lopencv_features2d300 ...
edit retag close merge delete

Following the update, isn't this solved? If so, we should mark it

( 2015-10-06 13:39:26 -0500 )edit

^^ just do it ;)

( 2015-10-06 13:59:18 -0500 )edit

@berak: I didn't realize I was already able to do so. I feel powerful :P

( 2015-10-06 14:16:26 -0500 )edit

We are trying to remove as much closed topics as possible and replace them by solved ones :) @coderx7 could you accept the solution if it worked?

( 2015-10-07 05:52:00 -0500 )edit

@StevenPuttemans: that's ok. However I was not referring to @berak comment but to the update the OP added to his question (yes, at the very very end). It seems he was just missing one step

( 2015-10-07 05:55:15 -0500 )edit

Ow then I will simply delete this one, since this huge question was mainly due to configuration issues. @coderx7 let me know if you do not agree, then I will recover it!

( 2015-10-07 05:57:10 -0500 )edit
1

@StevenPuttemans: Please recover the question, Thats not the answer to my question, since if you see the question, specially the section I updated, you will notice that I had already done the suggested answer and it didn't work in qt, and the reason is explain ed at the end of the question. (I couldn't post an answer earlier, the answer to this question is know since yesterday.

( 2015-10-08 00:00:27 -0500 )edit

Could you then maybe reduce your question to the essentials? It is huge now and it if people need to open up the more button, then many will never read the actual problem :D

( 2015-10-08 03:38:56 -0500 )edit

Sort by » oldest newest most voted

"this fails as well : " - you're confusing the include folder(needed for the compile step) with the 'lib' folder (needed to link, later) , so try:

LIBS +=-L:/Apps_Installation_Folder/opencv/build/lib
LIBS += -lopencv_core300 -lopencv_highgui300 -lopencv_imgcodecs300  ...


also, just saying, it needs 2 backslashes or a single forward slash

more

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2015-10-06 09:23:03 -0500

Seen: 3,403 times

Last updated: Oct 06 '15