How to install Qt on Windows after building?

后端 未结 8 410
死守一世寂寞
死守一世寂寞 2020-12-02 09:55

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

相关标签:
8条回答
  • 2020-12-02 10:37

    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.

    0 讨论(0)
  • 2020-12-02 10:37

    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.

    0 讨论(0)
  • 2020-12-02 10:42

    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.

    0 讨论(0)
  • 2020-12-02 10:43

    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.

    0 讨论(0)
  • 2020-12-02 10:44

    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.

    0 讨论(0)
  • 2020-12-02 10:52

    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.

    0 讨论(0)
提交回复
热议问题