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

发布于 2024-10-11 20:40:25 字数 405 浏览 3 评论 0原文

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

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 Linux there's description of -prefix option in configure script 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

柳絮泡泡 2024-10-18 20:40:25

正如 Ismail 所说,Windows 上的 Qt 没有安装步骤。
然而,人们可以尝试通过执行以下操作来近似它。

  1. 清洁
    在构建文件夹中运行 make clean 以删除所有临时文件。
  2. 移动
    将构建文件夹复制到您想要“安装”Qt 的位置。我们将其命名为 INSTALL_DIR
  3. 修复 qmake.exe 可执行文件中硬编码的路径
    运行 qmake -query 以查看哪些路径被编译(硬编码)到 qmake 和
    一个。通过使用 qmake -set 将其替换为 INSTALL_DIR 来修复包含构建文件夹的路径 (1)。

    b.创建一个 qt.conf 文件INSTALL_DIR 的 bin 子文件夹,在其中指定新的 Qt 路径。
  4. 将当前目录添加到包含路径
    在 Qt 提供的二进制发行版中,pwd 包含在 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 子文件夹的新位置。

底线:
Windows 下 Qt 的构建过程使得构建后移动(安装)Qt 非常尴尬。只有当……好吧,我找不到任何好的理由来经历所有这些麻烦,你才应该这样做。

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

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

上述许多信息均来自 RelocationTricks Wiki 页面,作者:加布·鲁迪.查看他的Qt (Qt4) Opensource Windows Installers of Pre-built Binaries with MSVC 2008 项目可以让您轻松解决上述问题。

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

  1. Cleaning
    Run make clean in 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.exe executable
    Run qmake -query to see what paths are compiled (hardcoded) into qmake and
    a. Fix paths containing the build folder by replacing it with the INSTALL_DIR using qmake -set (1).
    or
    b. Create a qt.conf file in the bin subfolder of the INSTALL_DIR specifing 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_INCDIR and 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.conf file:
    QMAKE_INCDIR += "."
  5. Fixing prl files
    When you add a Qt component to a project file (such as CONFIG += uitools), Qt looks in %QTDIR%/lib/QtUiTools.prl to 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/*.prl files.
  6. Making source available
    If you made a shadow build (build made inside folder other than the one containg sources), headers in the include subfolder only forward to the original headers. For example; BUILD_DIR\include\QtCore\qabstractanimation.h looks 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/src subfolder to your destination folder and fix all headers in the include folder so that they forward to the new location of src subfolder.

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.

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.

1)
The variables you set with qmake -set are 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.conf file (actually files as you need one file for each Qt installation) (option 3b).

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

黯然#的苍凉 2024-10-18 20:40:25

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

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

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

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

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

对于初始移动,nmake "INSTALL_ROOT=\somewhere" install 对我有用。这就是 Piotr 答案的步骤 1 和 2。 FWIW,我不需要步骤 4 或 6。

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.

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

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

Replace <path> with the full path of your Qt directory after you moved it (the qtbase directory if you are using Qt 5). Omit the final qt5 argument if you are using 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.

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

街角迷惘 2024-10-18 20:40:25

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

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

then call:

nmake
nmake install

,后者会将 Qt 安装在 C:\the\path\I\want 中。

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

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

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

then call:

nmake
nmake install

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

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.

紫竹語嫣☆ 2024-10-18 20:40:25

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

我已经使用过它很多次了,我同意它与其他平台上的不同,但它达到了它的目的。

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

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

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

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

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

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

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):

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:

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.

清引 2024-10-18 20:40:25

Windows 上的 Qt 无法通过 make install 安装,您会注意到 Windows 上的 Qt 安装程序仅修补 dll 和 DLL。 pdbs 作为新的安装位置。

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

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.

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

倚栏听风 2024-10-18 20:40:25

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

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

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

然后作为最后一步(正如 Randy 善意指出的那样),您需要修补 qmake.exe,这可以使用名为 QtMove。该工具还会自动更新所有 prl 文件。

Qt's own build instructions show 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:

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:

[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 prl files.

哭了丶谁疼 2024-10-18 20:40:25

步骤 1:移动 Qt

  • 剪切和粘贴
  • 当前目录 - C:\tools\Qt
  • 目标目录 -C:\sim\dep\Qt

步骤 2:获取旧 Qt 目录

  • 转到 C:\sim\dep\Qt\2010.02.1\ Qt
  • 打开 .qmake.cache
  • 找到变量 QT_SOURCE_TREE
  • 注意 QT_SOURCE_TREE 的值
  • 我的是 C:\tools\Qt\2010.02.1\Qt

第三步:给 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

步骤 4:设置环境变量

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

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

Step 1: Move Qt

  • Cut and Paste
  • Current directory - C:\tools\Qt
  • Destination directory -C:\sim\dep\Qt

Step 2: Get Old Qt Directory

  • 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

Step 3: Patch 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

Step 4: Set Environment Variables

  • 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

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.

染火枫林 2024-10-18 20:40:25

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

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

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文