How to install Qt on Windows after building?

2019-01-10 09:56发布

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.

8条回答
男人必须洒脱
2楼-- · 2019-01-10 10:34

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.

查看更多
别忘想泡老子
3楼-- · 2019-01-10 10:34

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.

查看更多
beautiful°
4楼-- · 2019-01-10 10:42

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.

查看更多
可以哭但决不认输i
5楼-- · 2019-01-10 10:53

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.

查看更多
够拽才男人
6楼-- · 2019-01-10 10:53

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.

查看更多
兄弟一词,经得起流年.
7楼-- · 2019-01-10 10:54

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.

查看更多
登录 后发表回答