简体   繁体   中英

Qt Creator + OpenCV: Program runs from .exe but not from editor

Well, I need to start working with OpenCV and as I'm used to working with QtCreator, I'm trying to make it all work together. I downloaded the latest OpenCV version, and compiled it with MinGW. Then, I created this little console project to try it out. Below is the .pro file:

QT       += core
QT       -= gui
TARGET = OpenCV_test4
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
INCLUDEPATH += C:\\Librerias\\opencv2.3.1\\release\\include
LIBS += -LC:\\Librerias\\opencv2.3.1\\release\\lib \
    -lopencv_core231.dll \
    -lopencv_highgui231.dll \
    -lopencv_imgproc231.dll \
    -lopencv_features2d231.dll \
    -lopencv_calib3d231.dll

Here is the main.cpp file:

#include <QtCore/QCoreApplication>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    // read an image
    cv::Mat image= cv::imread("img.jpg");
    // create image window named "My Image"
    cv::namedWindow("OpenCV Window");
    // show the image on window
    cv::imshow("OpenCV Window", image);
    // wait key for 5000 ms
    cv::waitKey(5000);

    return a.exec();
}

(I have tried this code with and without the QCoreApplication lines)

The deal is: It links and builds, and when runs from QtCreator only a terminal window called C:\\QtSDK\\QtCreator\\bin\\qtcreator_process_stub.exe appears with the line "Press RETURN to close this window..."

But, if I run the .exe from the project folder, it runs perfectly!! Why is QtCreator unable to launch the application? I found this really strange, and I would appreciate any hint about this. It's really not THAT important, but it is kind of a pain to have to run the .exe manually every time I change something to check how it works.

Thanks for your time :)

Additional Info:

  • I have tried both debug and release versions, the problem is the same in both of them.
  • Debugging does not work, it never stops at any breakpoint.
  • I'm running on Windows 7 Proffesional x64

SOLVED, I don't really know what I did, it suddenly worked and keeps working, I wish I could tell you how I fixed it but I have no idea, such a weird thing :(

Check Projects -> Run Settings -> Run in terminal. It have to be enabled, but seems to be disabled.

I have met same problem with QtCreator and OpenCL under Linux. Simple test program works after start from terminal and it does not work after start from the QtCreator. I found the cause was hardcoded LD_LIBRARY_PATH in the project's run environment settings. I had dropped it to empty string and this had fixed issue.

I had the same issue with the following environment: Raspbian, Qt, openCV and a gui application.

old-ufo recommendation worked for me: - First, enable "Run in terminal", which failed - Then, disable "Run in terminal", which allowed me to correctly debug my app.

I understand that this is not scientific.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM