Qt 创建者 + OpenCV:程序从 .exe 运行,但不是从编辑器运行
好吧,我需要开始使用 OpenCV,并且由于我习惯了使用 QtCreator,我正在努力让它们一起工作。我下载了最新的OpenCV版本,并用MinGW编译它。然后,我创建了这个小控制台项目来尝试一下。下面是 .pro
文件:
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
这是 main.cpp
文件:(
#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();
}
我已经尝试过使用和不使用 QCoreApplication
行的代码
)处理是:它链接并构建,当从 QtCreator 运行时,只会出现一个名为 C:\QtSDK\QtCreator\bin\qtcreator_process_stub.exe
的终端窗口,并显示行“Press RETURN”关闭此窗口...”
但是,如果我从项目文件夹运行 .exe,它会完美运行!为什么 QtCreator 无法启动应用程序?我发现这真的很奇怪,如果有任何关于这一点的提示,我将不胜感激。这确实不是那么重要,但是每次我更改某些内容以检查其工作原理时都必须手动运行 .exe,这有点痛苦。
感谢您的宝贵时间:)
其他信息:
- 我已经尝试过调试版本和发布版本,这两个版本的问题都是相同的。
- 调试不起作用,它永远不会在任何断点处停止。
- 我正在 Windows 7 Proffesional x64 上运行
,已解决,我真的不知道我做了什么,它突然工作并继续工作,我希望我能告诉你我是如何修复它的,但我不知道,这是一个奇怪的事情:(
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 :(
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
检查项目->运行设置->在终端中运行。必须启用它,但似乎已禁用。
Check Projects -> Run Settings -> Run in terminal. It have to be enabled, but seems to be disabled.
我在 Linux 下使用 QtCreator 和 OpenCL 时遇到了同样的问题。简单的测试程序在从终端启动后可以工作,但在从 QtCreator 启动后不起作用。
我发现原因是项目的运行环境设置中硬编码了 LD_LIBRARY_PATH。我已将其放入空字符串,这解决了问题。
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.
我在以下环境中遇到了同样的问题:Raspbian、Qt、openCV 和 gui 应用程序。
旧的不明飞行物推荐对我有用:
- 首先,启用“在终端中运行”,但失败
- 然后,禁用“在终端中运行”,这使我能够正确调试我的应用程序。
我明白这是不科学的。
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.