简体   繁体   English

使用 Qt 的程序,从 VS 启动时 OpenCV 运行良好,但在使用 OpenCV 功能时运行可执行文件通常会崩溃

[英]Program using Qt, OpenCV runs fine when started from VS, but running the executable ordinarily crashes when OpenCV functionality would be used

I'm trying to deploy my C++ program.我正在尝试部署我的 C++ 程序。 Every functionality of it works if I run the program from the VS IDE (release mode).如果我从 VS IDE(发布模式)运行程序,它的每个功能都可以工作。 When I ordinarily run the same executable, the main window comes up fine and its non-OpenCV functionality works;当我通常运行相同的可执行文件时,主窗口正常运行并且其非 OpenCV 功能正常工作; but when I try to open a picture and have the program use OpenCV stuff (opening it invokes the use of several OpenCV manipulations on the picture), it crashes.但是当我尝试打开一张图片并让程序使用 OpenCV 的东西时(打开它会调用对图片的几个 OpenCV 操作),它崩溃了。

I ran windeployqt from the Developer Command Prompt for VS 2017 successfully.我从 VS 2017 的开发人员命令提示符成功运行了windeployqt It didn't copy the OpenCV dlls next to my executable, though, so I copied opencv_world400.dll and opencv_ffmpeg400_64.dll next to the other dlls.不过,它没有复制我的可执行文件旁边的 OpenCV dll,所以我复制了其他 dll 旁边的opencv_world400.dllopencv_ffmpeg400_64.dll I assume this is the step where I'm missing something.我认为这是我遗漏了一些东西的步骤。 The folder looks like this now:该文件夹现在看起来像这样:可执行文件的文件夹

I'm using VS2017 with Qt5.10.1 and OpenCV4.0.我将 VS2017 与 Qt5.10.1 和 OpenCV4.0 一起使用。 I don't think I can insert relevant code as the project is quite big and it uses OpenCV functionality extensively.我不认为我可以插入相关代码,因为该项目非常大并且广泛使用 OpenCV 功能。

I figured it out, the problem was unrelated to OpenCV ( opencv_world400.dll was sufficient to copy into the folder).我想通了,问题与 OpenCV 无关( opencv_world400.dll足以复制到文件夹中)。

The problem was: I used Qt's applicationDirPath() , which returns the executable's path, to access a Results folder I was supposed to have previously created there, but did not.问题是:我使用 Qt 的applicationDirPath() ,它返回可执行文件的路径,来访问我之前应该在那里创建的结果文件夹,但没有。 The program, if ran from VS, was accessing the existing Results folder in the Debug folder, even though I was running the program in release mode and applicationDirPath() was returning the executable's path in the Release folder.该程序(如果从 VS 运行)正在访问Debug文件夹中现有的Results文件夹,即使我在发布模式下运行该程序并且applicationDirPath()正在返回Release文件夹中的可执行文件的路径。 When I was running the same executable ordinarily, it couldn't find the Results folder and crashed.当我通常运行相同的可执行文件时,它找不到结果文件夹并崩溃了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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