When I use imread function in basic qt application, the app crashes.
My pro file
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = lab1
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp
HEADERS += mainwindow.h
FORMS += mainwindow.ui
INCLUDEPATH += /usr/local/include/opencv
INCLUDEPATH += /usr/local/include
INCLUDEPATH += /usr/local/include/opencv2
LIBS += -L/usr/local/lib
LIBS += -lopencv_core
LIBS += -lopencv_imgproc
LIBS += -lopencv_highgui
LIBS += -lopencv_ml
LIBS += -lopencv_video
LIBS += -lopencv_features2d
LIBS += -lopencv_calib3d
LIBS += -lopencv_objdetect
LIBS += -lopencv_contrib
LIBS += -lopencv_legacy
LIBS += -lopencv_flann
LIBS += -lopencv_nonfree
LIBS += `pkg-config opencv --libs`
Code
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_actionSave_changed()
{
cv::Mat img;
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),"",tr("Files (*.*)"));
img = cv::imread("image.jpg", CV_LOAD_IMAGE_UNCHANGED);
}
Error
Starting /home/yaltug/Desktop/yavuzlab1/build-lab1-Desktop_Qt_5_2_1_GCC_64bit-Debug/lab1... * glibc detected * /home/yaltug/Desktop/yavuzlab1/build-lab1-Desktop_Qt_5_2_1_GCC_64bit-Debug/lab1: realloc(): invalid pointer: 0x00007f752cd1cd80 * ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7f752be10b96] /lib/x86_64-linux-gnu/libc.so.6(realloc+0x28e)[0x7f752be1589e] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(_ZN9QListData7reallocEi+0x26)[0x7f752c758016] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(_ZN9QListData6appendEi+0x65)[0x7f752c7580d5] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(+0x8dba6)[0x7f752c6f5ba6] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(+0x8bd17)[0x7f752c6f3d17] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(+0x8c9c5)[0x7f752c6f49c5] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(_Z20qMessageFormatString9QtMsgTypeRK18QMessageLogContextRK7QString+0x742)[0x7f752c6f5252] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(+0x8d405)[0x7f752c6f5405] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(+0x8a883)[0x7f752c6f2883] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(+0x8a9da)[0x7f752c6f29da] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(_ZNK14QMessageLogger5fatalEPKcz+0xa9)[0x7f752c6f3109] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(_ZN9QMetaType22registerNormalizedTypeERK10QByteArrayPFvPvEPFS3_PKvES5_PFS3_S3_S7_Ei6QFlagsINS_8TypeFlagEEPK11QMetaObject+0x567)[0x7f752c8fec47] /home/yaltug/Qt5.2.1/5.2.1/gcc_64/lib/libQt5Core.so.5(_ZN9QMetaType12registerTypeEPKcPFvPvEPFS2_PKvES4_PFS2_S2_S6_Ei6QFlagsINS_8TypeFlagEEPK11QMetaObject+0x61)[0x7f752c8fed01]
7fffa4005000-7fffa4026000 rw-p 00000000 00:00 0 [stack] 7fffa4104000-7fffa4106000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] The program has unexpectedly finished.