简体   繁体   English

从批处理文件启动 Qt 应用程序

[英]Launch Qt application from batch file

I have developed an application in Qt and outside Qt Creator, when I run this application, it works.我在 Qt 和 Qt Creator 之外开发了一个应用程序,当我运行这个应用程序时,它可以工作。 But when I use a batch-file to execute the application I get this error:但是当我使用批处理文件执行应用程序时,我收到此错误:

The application failed to start because it could not find or load the Qt platform plugin "Windows应用程序无法启动,因为它无法找到或加载 Qt 平台插件“Windows

I have included all the dll including platform/qwindows.dll, but I cannot understand what the problem is.我已经包含了包括 platform/qwindows.dll 在内的所有 dll,但我不明白问题是什么。 Any idea what could be wrong?知道有什么问题吗?

Before, I thought that I have used an external library which is not set properly, but after removing the external library for testing purpose, the problem persists.之前,我以为我使用了一个没有正确设置的外部库,但是出于测试目的删除了外部库后,问题仍然存在。

The contents of the batch files are:批处理文件的内容是:

@echo off

set VMT=\\serverName\DEV
set BC_VERSION=v1.0

echo Test release of BeamConfigurator %BC_VERSION%

set BC_HOMEDIR=%VISMT%\BeamConfigurator\%BC_VERSION%
set BC_BINDIR=%ABC_HOMEDIR%\bin

echo %BC_BINDIR%

start /WAIT /B /LOW %BC_BINDIR%\BeamConfigurator.exe

It looks like your executable is trying to access the hardcoded (which Qt Creator does) library paths.看起来您的可执行文件正在尝试访问硬编码(Qt Creator 所做的)库路径。 If you have copied all the dll files required to run your executable to the same directory as your executable, try this.如果您已将运行可执行文件所需的所有dll文件复制到与可执行文件相同的目录中,请尝试此操作。

Create a file named qt.conf and place it in the same directory as your executable.创建一个名为qt.conf的文件并将其放在与可执行文件相同的目录中。 Add the required stuff like this.像这样添加所需的东西。

[Paths]
Prefix = /some/path
Translations = i18n
Plugins = plugins

More info can be found here更多信息可以在这里找到

The problem was that one of my colleague had added the following line in the main function while testing something.问题是我的一位同事在测试某些东西时在主函数中添加了以下行。

QCoreApplication::addLibraryPath("./");

After removing this line, it started to work with the batch file.删除此行后,它开始使用批处理文件。 But i still did not understand why there was a problem only when we launched it from the batch file.但是我仍然不明白为什么只有当我们从批处理文件启动它时才会出现问题。 even though i had put the batch file in the same folder as executable.即使我已将批处理文件与可执行文件放在同一文件夹中。

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

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