我使用Qt Creator 2.2.1和Qt 4.7.4(32位)构建了一个程序,其输出是可执行文件.使用DependencyWalker打开exe,它显示exe使用以下DLL:
> KERNEL32.DLL
> MSVCRT.DLL
> MINGWM10.DLL
> LIBGCC_S_DW2-1.DLL
> QTCORE4.DLL
> QTGUI4.DLL
我想要构建所有依赖文件(在其他项目中可能有所不同),除了Windows特定文件(上述列表中的前两个)将被自动复制到exe所在的目录中.
在Qt Creator或Qt系统中如何使用命令行脚本?谢谢.
解决方法
在QT 5.3中,您可以使用windeployqt qt工具自动复制所需的库.
项目的.pro文件的以下补充措施应该是诀窍,但是您可能需要根据您的具体情况进行一些调整.
isEmpty(TARGET_EXT) { win32 { TARGET_CUSTOM_EXT = .exe } macx { TARGET_CUSTOM_EXT = .app } } else { TARGET_CUSTOM_EXT = $${TARGET_EXT} } win32 { DEPLOY_COMMAND = windeployqt } macx { DEPLOY_COMMAND = macdeployqt } CONFIG( debug,debug|release ) { # debug DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/debug/$${TARGET}$${TARGET_CUSTOM_EXT})) } else { # release DEPLOY_TARGET = $$shell_quote($$shell_path($${OUT_PWD}/release/$${TARGET}$${TARGET_CUSTOM_EXT})) } # # Uncomment the following line to help debug the deploy command when running qmake # warning($${DEPLOY_COMMAND} $${DEPLOY_TARGET}) # Use += instead of = if you use multiple QMAKE_POST_LINKs QMAKE_POST_LINK = $${DEPLOY_COMMAND} $${DEPLOY_TARGET}