QT Directory Dependency problem----How to generate a green QT package
One, the core issues:
What if you copy the compiled QT file to any directory and use it as a green software library?
Second, the principle of discussion
Since QT hardcoded the installation path into the library file at compile time, this problem does not seem to be a good solution. Use the following command to see exactly which paths you have:
qmake -query
You can get a similar result as follows:
Qt_install_prefix:/usr/Lib/Qt4qt_install_data:/usr/Lib/Qt4qt_install_docs:/usr/Share/Doc/Qt4qt_install_headers:/usr/Includeqt_install_libs:/usr/Libqt_install_bins:/usr/Lib/Qt4/Binqt_install_plugins:/usr/Lib/Qt4/Pluginsqt_install_imports:/usr/Lib/Qt4/Importsqt_install_translations:/usr/Share/Qt4/translationsqt_install_configuration: /etcqt_install_examples:/usr/lib/qt4/examplesqt_install_demos: /usr/lib/qt4/ demosqmake_mkspecs:/usr/lib /qt4/mkspecsqmake_version :2.01aqt_version:4.7 4
Fortunately, a new mechanism was introduced in QT4: qt.conf, so the problem was solved. These paths can all be overwritten. See Qt.conf's help in assistant to learn about Qt.conf's general wording.
[Paths] Prefix = /some/path Translations = i18n
What happens if you place the above qt.conf in the directory where Qmake is located? Qmake-query will tell you the answer.
Qt_install_prefix:/some/Pathqt_install_data:/some/Pathqt_install_docs:/some/Path/Docqt_install_headers:/some/Path/Includeqt_install_libs:/some/Path/Libqt_install_bins:/some/Path/Binqt_install_plugins:/some/Path/Pluginsqt_install_imports:/some/path/:/some/path /i18nqt_install_configuration:/some/< Span class= "PLN" >pathqt_install_examples:/some/pathqt_ Install_demos:/some/pathqmake_mkspecs: /some/path/mkspecsqmake_version :2.01aqt_version:4.8 2
Thus, we can get the following conclusion: if there is a qt.conf file located under all directories of the QT executable, such as the/usr/bin directory, the search path for these executables will be overwritten by the path specified in the qt.conf. Prefix is the key, it specifies the root directory of QT, many other paths according to this path to specify some paths will have a default value, such as Lib,bin, and some are not, such as examples, demos
Third, the solution
For this reason, a reference qt.conf template is given below
[Paths]Prefix = /media/disk/qt-everywhere< Span class= "pun" >-opensource-src-4.8. 2translations =plugins = Plugins imports = Imports Examples = Examplesdemos = demos
The remaining problem is that every change of place, it is necessary to manually change, repetitive work is a bit uncomfortable. Here are two scripts for Windows and Linux respectively, after compiling QT, delete the largest src directory and then place the script in the root directory.
Windows version: Updateqt.bat
:::: ThisFile should be placedInch Qtroot directory::eg. IfQmake.ExeIs InchC:\qt\bInch, :: ThisScript should beInchC:\qt:::: Reference:http:www.cuteqt.com/blog/?p=149:: Reference:http:blog.csdn.net/jq0123/article/details/4325256RemGetCurrent DirectoryremandReplace \With /SET PWD=%~Dp0set CONF=%Pwd%\bInch\qt.Confset PWD=%Pwd:\=/%Echo[Paths] >%CONF%EchoPrefix = %pwd % >>%conf%echo Span class= "Typ" >translations = translations >>%conf%echo Examples = Examples >>% conf%echo demos = demos >>%conf%
Linux version: updateqt.sh
#!/bin/bashfunction Scriptabsolutepath() {DIR=$(DirName' Which ')Echo $DIR}Prefix=' Scriptabsolutepath 'Translations=TranslationsPlugins=PluginsImports=ImportsExamples=ExamplesDemos=Demosconf=$Prefix/Bin/Qt.Confecho[Paths] >$CONFechoPrefix =$Prefix>> $CONFecho translations = $Translations >> $CONFecho plugins< Span class= "PLN" > = $Plugins >>$ Confecho imports = $Imports >> $CONFecho examples= $Examples >> $CONFecho demos = $Demos >> $CONF
Iv. Summary
If you compile a QT library, you can implement the following steps:
- Delete src directory, there are some source code and temporary files. You can also delete some other unrelated directories, but none of them are big or harmless.
- In the root directory, write the script updateqt.bat or updateqt.sh, as follows.
- Execute the script every time you copy the entire directory to another location.
- Add the Qt Bin directory to the system path. This way, other software can find Qmake, and then it can automatically find the location of the library file (Lib) and the header file (include).
Then you get an approximate green qt release. Every time you change a place, you just need to execute the script.
Note: this mechanism is not for QT4,QT3 only.
http://www.ituring.com.cn/article/5485
QT Directory Dependency problem----How to generate a green QT package