windows 构建后如何在Windows上安装Qt?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4699311/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:58:57  来源:igfitidea点击:

How to install Qt on Windows after building?

windowsqtconfigurationinstallationmake-install

提问by Piotr Dobrogost

I can't find any information on how to install Qt built on Windows.
In wiki article How to set up shadow builds on Mac and Linuxthere's description of -prefixoption in configurescript but this option is not available on Windows.
I know I can use Qt right from the build folder but it does not seem the right thing not to perform an install step. One problem with this approach is size; Qt's build folder takes about 4GB space whereas after installing using binary installer Qt takes about 1GB space. I guess the difference is due to temporary files created during building. I hope some install procedure would install (copy) only needed files leaving temporary files in the build folder.

我找不到有关如何安装在 Windows 上构建的 Qt 的任何信息。
在维基文章如何在 Mac 和 Linux 上设置影子构建中有脚本-prefix选项的描述,configure但此选项在 Windows 上不可用。
我知道我可以直接从构建文件夹中使用 Qt,但不执行安装步骤似乎不是正确的做法。这种方法的一个问题是尺寸;Qt 的构建文件夹大约需要 4GB 空间,而在使用二进制安装程序安装后,Qt 大约需要 1GB 空间。我想差异是由于构建过程中创建的临时文件造成的。我希望一些安装过程会安装(复制)只需要的文件,而在构建文件夹中留下临时文件。

回答by Piotr Dobrogost

As ?smail said there's no install step for Qt on Windows. However one can try to approximate it by performing the following operations.

正如 ?smail 所说,在 Windows 上没有 Qt 的安装步骤。但是,可以尝试通过执行以下操作来近似它。

  1. Cleaning
    Run make cleanin the build folder to remove all temporary files.
  2. Moving
    Copy build folder to the place where you want Qt "installed". Let's call it INSTALL_DIR.
  3. Fixing paths hardcoded in the qmake.exeexecutable
    Run qmake -queryto see what paths are compiled (hardcoded) into qmake and
    a. Fix paths containing the build folder by replacing it with the INSTALL_DIRusing qmake -set(1).
    or
    b. Create a qt.conffile in the bin subfolder of the INSTALL_DIRspecifing new Qt paths inside it.
  4. Adding current directory to include path
    In Qt's provided binary distributions, the pwd is included in the QMAKE_INCDIRand thus ends up in your projects include path as ".". This does not happen by default in a custom built Qt, so you have to add the following line to mkspecs/YOUR-PLATFORM-HERE/qmake.conffile:
    QMAKE_INCDIR += "."
  5. Fixing prlfiles
    When you add a Qt component to a project file (such as CONFIG += uitools), Qt looks in %QTDIR%/lib/QtUiTools.prlto find the library dependencies of that component. These files will have the hard coded path of the directory in which Qt was configured and built. You have to replace that build directory with the one to which you moved Qt for all lib/*.prlfiles.
  6. Making source available
    If you made a shadow build (build made inside folder other than the one containg sources), headers in the includesubfolder only forwardto the original headers. For example; BUILD_DIR\include\QtCore\qabstractanimation.hlooks like this
    #include "SRC_DIR/src/corelib/animation/qabstractanimation.h"
    If you don't want to depend on the existence of the folder containg sources you have to copy SRC_DIR/srcsubfolder to your destination folder and fix all headers in the includefolder so that they forward to the new location of srcsubfolder.
  1. 清理在构建文件夹中
    运行make clean以删除所有临时文件。

  2. Copy build 文件夹移动到您想要“安装”Qt 的位置。让我们称之为INSTALL_DIR
  3. 修复在qmake.exe可执行文件中硬编码的路径
    运行qmake -query以查看哪些路径被编译(硬编码)为 qmake 和
    a. 通过将其替换为INSTALL_DIRusing qmake -set(1)来修复包含构建文件夹的路径。

    B. qt.conf在其中指定INSTALL_DIR新 Qt 路径的 bin 子文件夹中创建一个文件。
  4. 添加当前目录以包含路径
    在 Qt 提供的二进制发行版中,密码包含在 中QMAKE_INCDIR,因此在您的项目中最终包含路径为“.”。在自定义构建的 Qt 中默认情况下不会发生这种情况,因此您必须将以下行添加到mkspecs/YOUR-PLATFORM-HERE/qmake.conf文件中:
    QMAKE_INCDIR += "."
  5. 修复prl文件
    当您将 Qt 组件添加到项目文件(例如CONFIG += uitools)时,Qt 会查找%QTDIR%/lib/QtUiTools.prl该组件的库依赖项。这些文件将具有配置和构建 Qt 的目录的硬编码路径。您必须将该构建目录替换为您将 Qt 的所有lib/*.prl文件移动到的目录。
  6. 使源可用
    如果您进行了影子构建(在包含源的文件夹之外的文件夹中构建),则include子文件夹中的标题仅转发到原始标题。例如; BUILD_DIR\include\QtCore\qabstractanimation.h看起来像这样
    #include "SRC_DIR/src/corelib/animation/qabstractanimation.h"
    如果您不想依赖包含源的文件夹的存在,您必须将SRC_DIR/src子文件夹复制到目标文件夹并修复文件夹中的所有标题,include以便它们转发到src子文件夹的新位置。

The bottom line:
The build process of Qt under Windows makes it really akward to move (install) Qt after building. You should do this only if ... well I can't find any good reason to go through all this trouble.

底线:
Qt 在 Windows 下的构建过程使得在构建后移动(安装)Qt 真的很尴尬。只有在…… 好吧,我找不到任何好的理由来解决所有这些麻烦时,您才应该这样做。

Remember
The easy way is to place Qt's sources in the folder where you want Qt to stay after building and make a build in this folder. This makes all steps but 1 and 4 above unnecessary.

记住
最简单的方法是将 Qt 的源代码放在您希望 Qt 在构建后保留的文件夹中,并在此文件夹中进行构建。这使得除了上面的 1 和 4 之外的所有步骤都是不必要的。

1)
The variables you set with qmake -setare saved in the registry key
HKEY_CURRENT_USER\Software\Trolltech\QMake\<QMAKE_VERSION>.
Because of this you might have a problem when you would like to have different projects using different versions of Qt which happen to have the same version of qmake. In this case the better solution is to use qt.conffile (actually files as you need one file for each Qt installation) (option 3b).

1)
您设置的变量qmake -set保存在注册表项中
HKEY_CURRENT_USER\Software\Trolltech\QMake\<QMAKE_VERSION>
因此,当您希望使用不同版本的 Qt 的不同项目恰好具有相同版本的 qmake 时,您可能会遇到问题。在这种情况下,更好的解决方案是使用qt.conf文件(实际上是文件,因为每个 Qt 安装都需要一个文件)(选项 3b)。

Many of the information above come from the RelocationTrickswiki page authored by Gabe Rudy. Check out his Qt (Qt4) Opensource Windows Installers of Pre-built Binaries with MSVC 2008project which gives you easy solution of above problems.

以上许多信息来自Gabe Rudy 撰写的RelocationTrickswiki 页面。查看他的Qt (Qt4) Opensource Windows Installers of Pre-built Binaries with MSVC 2008项目,它为您提供了上述问题的简单解决方案。

回答by Oktalist

This answer is a replacement for steps 3 and 5 of Piotr's (currently top rated) answer above, but you may still need the other steps in his answer, depending what you're trying to achieve.

此答案替代了上面 Piotr(目前评分最高)答案的第 3 步和第 5 步,但您可能仍需要他的答案中的其他步骤,具体取决于您要实现的目标。

To summarize: after moving your Qt directory to where you want it, download any one of the official Qt installersand run it with the following commandline arguments:

总结一下:将 Qt 目录移动到您想要的位置后,下载任何官方 Qt安装程序并使用以下命令行参数运行它:

cd <path>
installer.exe --runoperation QtPatch windows <path> qt5

Replace <path>with the full path of your Qt directory after you moved it (the qtbasedirectory if you are using Qt 5). Omit the final qt5argument if you are using Qt 4.

移动后替换<path>为 Qt 目录的完整路径(qtbase如果您使用的是 Qt 5,则为该目录)。qt5如果您使用 Qt 4,请省略最后一个参数。

This will fix the hardcoded paths in qmake.exe, .prl files, and others. It gives you the exact same behaviour that the official installers have in that respect.

这将修复 qmake.exe、.prl 文件和其他文件中的硬编码路径。它为您提供与官方安装程序在这方面完全相同的行为。

For the initial move, nmake "INSTALL_ROOT=\somewhere" installworks for me. So that's steps 1 and 2 of Piotr's answer covered. And I haven't needed steps 4 or 6, FWIW.

对于最初的举动,nmake "INSTALL_ROOT=\somewhere" install对我有用。这就是 Piotr 回答的第 1 步和第 2 步。而且我不需要第 4 步或第 6 步,FWIW。

回答by mic

I can configure QT 5 on WINDOWS (Visual Studio build) with the prefix option like:

我可以使用前缀选项在 WINDOWS(Visual Studio 构建)上配置 QT 5,例如:

configure -prefix C:\the\path\I\want ...

then call:

然后调用:

nmake
nmake install

and the latter will install Qt in C:\the\path\I\want.

后者将在 C:\the\path\I\wan 中安装 Qt。

I did it without problems with Qt 5.2.1 and 5.3.x, so far. So, any earlier problems seem to be fixed by now.

到目前为止,我在 Qt 5.2.1 和 5.3.x 上没有问题。因此,任何早期的问题现在似乎都已解决。

回答by rubenvb

It's very odd people claim that there is no "make install" on Windows.

人们声称 Windows 上没有“make install”,这很奇怪。

I have used it many times, and I agree that it's not what it is on other platforms, but it serves its purpose.

我已经多次使用它,我同意它在其他平台上不是这样,但它达到了它的目的。

How I use Qt's make install on Windows (from cmd):

我如何在 Windows 上使用 Qt 的 make install(来自 cmd):

configure
(n/mingw32-)make
(n/mingw32-)make docs
(n/mingw32-)make install

The make install bit copies all necessary headers to be able to delete your source directory. Delete all objects and unecessary stuff:

make install 位复制所有必要的头文件,以便能够删除您的源目录。删除所有对象和不必要的东西:

del /S /Q *.obj lib\*.dll
rmdir /S /Q docs-build qmake tools src

This allows you to remove the source directory. I don't know what impact this has on debugging Qt source code, but it sure reduces the size of a shadow build. I use it to maintain 32 and 64 bit builds with minimal size.

这允许您删除源目录。我不知道这对调试 Qt 源代码有什么影响,但它确实减少了影子构建的大小。我用它来维护 32 位和 64 位的最小尺寸的构建。

回答by ismail

Qt on Windows is not installable with make install, you will notice that Qt installer for Windows just patches dlls & pdbs for the new install location.

Windows 上的 Qt 无法安装make install,您会注意到 Windows 的 Qt 安装程序只是为新安装位置修补 dll 和 pdb。

What I would suggest is to do a shadow build in the place you would like to install it. You can manually remove *.objfiles to save up space.

我的建议是在你想安装它的地方做一个影子构建。您可以手动删除*.obj文件以节省空间。

回答by Saul

Qt's own build instructionsshow how this is done, by search/replace within each Makefile. Assuming the source was extracted to C:\qt-4.8.3 and build was performed within that directory, then do this:

Qt 自己的构建说明通过在每个 Makefile 中搜索/替换来显示这是如何完成的。假设源被解压到 C:\qt-4.8.3 并在该目录中执行构建,然后执行以下操作:

fart -c -i -r Makefile* $(INSTALL_ROOT)\qt-4.8.3 $(INSTALL_ROOT)\my-install-dir
set INSTALL_ROOT=
mingw32-make install

Then create a config file that tells qmake about its new installation path. Create a textfile C:\my-install-dir\bin\qt.conf:

然后创建一个配置文件,告诉 qmake 其新安装路径。创建一个文本文件 C:\my-install-dir\bin\qt.conf:

[Paths]
Prefix=C:/my-install-dir
Translations = translations

Then as a final step (as Randy kindly pointed out) you need to patch qmake.exe, which can be done using a simple utility called QtMove. This same tool also automatically updates all the prlfiles.

然后作为最后一步(正如 Randy 亲切指出的那样),您需要修补 qmake.exe,这可以使用一个名为QtMove的简单实用程序来完成。同样的工具还会自动更新所有prl文件。

回答by Binh Nguyen

Step 1: Move Qt

第 1 步:移动 Qt

  • Cut and Paste
  • Current directory - C:\tools\Qt
  • Destination directory -C:\sim\dep\Qt
  • 剪切和粘贴
  • 当前目录 - C:\tools\Qt
  • 目标目录 -C:\sim\dep\Qt

Step 2: Get Old Qt Directory

第 2 步:获取旧的 Qt 目录

  • Go to C:\sim\dep\Qt\2010.02.1\Qt
  • Open .qmake.cache
  • Find variable QT_SOURCE_TREE
  • Note the value of QT_SOURCE_TREE
  • Mine was C:\tools\Qt\2010.02.1\Qt
  • 转到 C:\sim\dep\Qt\2010.02.1\Qt
  • 打开 .qmake.cache
  • 查找变量 QT_SOURCE_TREE
  • 注意 QT_SOURCE_TREE 的值
  • 我的是 C:\tools\Qt\2010.02.1\Qt

Step 3: Patch Qt

第 3 步:修补 Qt

  • Go to C:\sim\dep\Qt\2010.02.1\bin
  • The syntax is qpatch.exe list oldDir newDir
  • qpatch.exe files-to-patch-windows C:\tools\Qt\2010.02.1\Qt C:\sim\dep\Qt\2010.02.1\Qt
  • 转到 C:\sim\dep\Qt\2010.02.1\bin
  • 语法是 qpatch.exe list oldDir newDir
  • qpatch.exe files-to-patch-windows C:\tools\Qt\2010.02.1\Qt C:\sim\dep\Qt\2010.02.1\Qt

Step 4: Set Environment Variables

步骤 4:设置环境变量

  • set QTDIR=C:\sim\dep\Qt\2010.02.1\Qt
  • set QMAKESPEC=C:\sim\dep\Qt\2010.02.1\Qt\mkspecs\win32-g++
  • set PATH=%path%;C:\sim\dep\Qt\2010.02.1\Qt\bin
  • set PATH=%path%;C:\sim\dep\Qt\2010.02.1\bin
  • 设置 QTDIR=C:\sim\dep\Qt\2010.02.1\Qt
  • 设置 QMAKESPEC=C:\sim\dep\Qt\2010.02.1\Qt\mkspecs\win32-g++
  • set PATH=%path%;C:\sim\dep\Qt\2010.02.1\Qt\bin
  • set PATH=%path%;C:\sim\dep\Qt\2010.02.1\bin


You can do all of this with a batch file. This took me a fair while to work out and it has saved me a lot of time since. It's a script to automatically update a Qt installation to new locations. The batch file is available here.

您可以使用批处理文件完成所有这些操作。这花了我很长时间来锻炼,从那以后它为我节省了很多时间。这是一个自动将 Qt 安装更新到新位置的脚本。批处理文件可在此处获得

回答by Randy

There is a simple utility QtMove (http://www.runfastsoft.com) can do this easily.

有一个简单的实用程序 QtMove (http://www.runfastsoft.com) 可以轻松完成此操作。

Runs the relocated qmake.exe build your .pro file and everything should be linked with new Qt libs.

运行重新定位的 qmake.exe 构建您的 .pro 文件,所有内容都应与新的 Qt 库链接。