QtCreator5.3.1使用opencv显示图像,**crash

首先,在windows7系统里,成功安装了QtCreator5.3.1与opencv2.4.9,且通过cmake编译,搭建QtCreator与opencv环境。
代码如下
①xxx.pro
#-------------------------------------------------
#

Project created by QtCreator 2017-11-09T10:20:23

#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = exam1
TEMPLATE = app

SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h
FORMS += mainwindow.ui

INCLUDEPATH += D:\opencv\build\include \
D:\opencv\build\include\opencv \
D:\opencv\build\include\opencv2 \

INCLUDEPATH += $$PWD/../../../opencv/MinGw/include
DEPENDPATH += $$PWD/../../../opencv/MinGw/include
LIBS += -L$$PWD/../../../opencv/MinGw/lib/
LIBS += -llibopencv_contrib249 \
-llibopencv_calib3d249 \
-llibopencv_core249 \
-llibopencv_features2d249 \
-llibopencv_flann249 \
-llibopencv_gpu249 \
-llibopencv_highgui249 \
-llibopencv_imgproc249 \
-llibopencv_legacy249 \
-llibopencv_video249 \
-llibopencv_objdetect249 \
②主程序
#include "mainwindow.h"
#include
#include

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();

}
③#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// ui->setupUi(this);
cvNamedWindow("screen",1);
while(1);
IplImage *img = cvLoadImage("D:\Qt\example\icon\screen.jpg");
cvShowImage("screen",img);
while(1){

    if( 27 == cvWaitKey(0) )
        break;
}
cvReleaseImage(&img);
cvDestroyWindow("screen");

}

MainWindow::~MainWindow()
{
delete ui;
}

运行结果:
Starting D:\Qt\example\build-exam1-Desktop_Qt_5_3_MinGW_32bit-Release\release\exam1.exe...
程序异常结束。
D:\Qt\example\build-exam1-Desktop_Qt_5_3_MinGW_32bit-Release\release\exam1.exe crashed

注:图片路径正确,能够正确使用。求大神帮忙!!!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问