Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Windows 从批处理文件运行portable Qt app可执行文件_Windows_Qt_Batch File - Fatal编程技术网

Windows 从批处理文件运行portable Qt app可执行文件

Windows 从批处理文件运行portable Qt app可执行文件,windows,qt,batch-file,Windows,Qt,Batch File,将文件移动到其他驱动器时,Windows快捷方式具有取消引用的绝对路径。我希望用户单击与子目录中所有Qt dll文件分离的文件,而不是快捷方式 我已经创建了一个批处理文件,位于可执行文件上方的1个目录中,具有运行该文件的相对路径 release + db + plugins + platforms + iconengines + imageformats - Qt5Core.dll - program.

将文件移动到其他驱动器时,Windows快捷方式具有取消引用的绝对路径。我希望用户单击与子目录中所有Qt dll文件分离的文件,而不是快捷方式

我已经创建了一个批处理文件,位于可执行文件上方的1个目录中,具有运行该文件的相对路径

release
     + db
     + plugins
         + platforms
         + iconengines
         + imageformats
     - Qt5Core.dll
     - program.exe
     - etc....
program.bat

//paths set in main()
QCoreApplication::AddLibraryPath("plugins");
我发现以下代码来自:

但运行时,会显示错误消息“windows找不到…”

我也试过了

@start "" "release\program.exe"

@start "" "%CD%\release\program.exe"

@start "" "%~dp0\release\program.exe"
但是我得到一个关于Qt没有找到“windows”平台插件的错误,这似乎表明路径有问题


为什么程序使用windows快捷方式正常运行,而批处理文件失败

我已经在我的程序的父文件夹中创建了program.bat,其中包含您的内容,它可以工作

在未安装Qt的机器上进行了测试。操作系统是Windows7

这是一个示例应用程序结构

bin
     + platforms
     + iconengines
     + imageformats
     - Qt5Core.dll
     - program.exe
     - etc....
program.bat
program.bat包含:

@start "" "bin\program.exe"
因此,请确保您的应用程序部署良好。

我在我的pro文件中使用此选项,以确保每个版本都正确部署:

# Deployment
CONFIG (release, release|debug) {
win32 {
        QMAKE_POST_LINK = windeployqt $${DESTDIR}/$${TARGET}.exe --no-translations
        # Not necessary when path to VC libraries is correctly set
        externalLibs.files += somepath/_windeploy_/msvcr120.dll
        externalLibs.files += somepath/_windeploy_/msvcp120.dll
        externalLibs.path = $$DESTDIR
        # need to add additional build step (make): install
        INSTALLS += externalLibs
    }
}

您的程序在不从QtCreator运行时运行吗?您的程序路径中是否有此文件:release/platforms/qwindows.dll?我之所以这样问,是因为快捷方式可能使用您的环境设置,其中有Qt的路径,所以它会找到所需的所有dll,批处理文件是否可以有“clean environment”这就是为什么你的程序会抱怨缺少插件。试着在干净的环境下运行这个程序,也许它也会失败,问题出在其他地方。我稍微编辑了一下我的问题。是否可以按原样添加部署代码?您应该找到程序的路径。我使用DESTDIR变量,所以它适用于我所有的win项目。如果消息($${DESTDIR}/$${TARGET}.exe)指向您的可执行文件,请尝试添加此消息。如果不修改或尝试修改windeploy的路径,或只是在发布文件夹的命令行中运行windeployqt program.exe。
# Deployment
CONFIG (release, release|debug) {
win32 {
        QMAKE_POST_LINK = windeployqt $${DESTDIR}/$${TARGET}.exe --no-translations
        # Not necessary when path to VC libraries is correctly set
        externalLibs.files += somepath/_windeploy_/msvcr120.dll
        externalLibs.files += somepath/_windeploy_/msvcp120.dll
        externalLibs.path = $$DESTDIR
        # need to add additional build step (make): install
        INSTALLS += externalLibs
    }
}