Ask Your Question

simple image display code not working in qt creator

asked 2013-03-16 09:00:19 -0600

Capton gravatar image

Hello everyone, I'm running a a simple image display program with opencv in QtCreator but whenever i run the code it opens a console(qtcreator_process_stub.exe),says press<return> to close window and then nothing happens Please i need help Below is my code:


#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
int main() {
Mat image= imread("imgage.jpg");
namedWindow("My Image");
imshow("My Image", image);
return 1;

.PRO file:

QT += core
TARGET = opencv
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp
INCLUDEPATH += C:/opencv/build_with_Qt/debug/include
LIBS += -LC:/opencv/build_with_Qt/debug/lib \
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-04-06 12:47:33 -0600

fuego gravatar image

Did you find a solution because i have the same problem ! I have exactly the same code.

edit flag offensive delete link more

answered 2013-04-06 13:19:06 -0600

Basically you are using a relative path for your image. Put your image in your basic drive and use the absolute path. See if that works out for you.

Also place a debug point after the imread function and check if your Mat element actually contains data.

Also you have probably a type in the name of your image, it is now imgage, and i guess it should be image. This could also be a problem.

Also, change waitKey(5000) to waitKey(0) so that you actually have to push the button to close everything down. You can then see if there is actually something displayed in your window.

edit flag offensive delete link more

Question Tools



Asked: 2013-03-16 09:00:19 -0600

Seen: 2,485 times

Last updated: Apr 06 '13