Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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   
Downloaded the OpenCV 3.0   
Downloaded the Cmake 3.3.2

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
 mymade
 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 :

enter image description here 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

HEADERS  += mainwindow.h


INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//*.lib

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

HEADERS  += mainwindow.h


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

LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_core300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_highgui300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_imgcodecs300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_ml300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_objdetect300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_photo300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_shape300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_hal300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_flann300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_features2d300.lib

FORMS    += mainwindow.ui

So what is the problem here? what am I missing ?

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   
Downloaded the OpenCV 3.0   
Downloaded the Cmake 3.3.2

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
 mymade
 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 :

enter image description here 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

HEADERS  += mainwindow.h


INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//*.lib

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

HEADERS  += mainwindow.h


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

LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_core300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_highgui300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_imgcodecs300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_ml300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_objdetect300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_photo300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_shape300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_hal300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_flann300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_features2d300.lib

FORMS    += mainwindow.ui

So what is the problem here? what am I missing ?

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   
Downloaded the OpenCV 3.0   
Downloaded the Cmake 3.3.2

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
 mymade
 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 :

enter image description here 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

HEADERS  += mainwindow.h


INCLUDEPATH += L://Apps_Installation_Folder//opencv//build//include
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//*.lib

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

HEADERS  += mainwindow.h


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

LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_core300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_highgui300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_imgcodecs300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_ml300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_objdetect300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_photo300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_shape300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_hal300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_flann300.lib
LIBS += L://Apps_Installation_Folder//opencv//mymade//lib//Release//opencv_features2d300.lib

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

HEADERS  += mainwindow.h


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

LIBS +=-L"L://Apps_Installation_Folder//opencv//mymade//lib//Release"
LIBS += -lopencv_core300 -lopencv_highgui300 -lopencv_imgcodecs300 -lopencv_ml300 -lopencv_objdetect300 -lopencv_photo300 -lopencv_hal300 -lopencv_shape300 -lopencv_flann300 -lopencv_features2d300


FORMS    += mainwindow.ui

So what is the problem here? what am I missing ?

Update :
Qt couldnt find the opencv dlls, And to solve this problem, one only needs to add the directory containing dlls to the PATH variable, there you are good to go and everything should be fine, at least this was my case;)