下載安裝包
http://download.qt.io/archive/qt/4.8/4.8.6/qt-everywhere-opensource-src-4.8.6.tar.gz
ubuntu18 安裝gcc 8,會導致編譯錯誤
Makefile:1624: recipe for target 'obj/release/pcre_exec.o' failed
make[1]: *** [obj/release/pcre_exec.o] Error 1
make[1]: 離開目錄“/home/dhtc/qt-everywhere-opensource-src-4.8.6/src/script”
Makefile:565: recipe for target 'sub-script-make_default-ordered' failed
make: *** [sub-script-make_default-ordered] Error 2
有時候在ubuntu18,20上會出現找不到gcc-4 g++-4的情況,可以考慮使用ubuntu16,或者14,ubuntu14上直接安裝gcc和g++就是4.8版本的。
安裝gcc , g++ 4.8版本
sudo apt-get install gcc-4.8
sudo apt-get install g++-4.8
添加gcc , g++編譯器版本控制選項
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 20
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 30
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 30
刪除命令爲
sudo update-alternatives --remove gcc /usr/bin/gcc-7
sudo update-alternatives --remove gcc /usr/bin/gcc-4.8
sudo update-alternatives --remove gcc /usr/bin/g++-7
sudo update-alternatives --remove gcc /usr/bin/g++-4.8
如果出現全刪除找不到gcc,可以用上面的添加命令添加。
切換不同版本gcc g++命令
sudo update-alternatives --config gcc
sudo update-alternatives --config g++
編譯Qt4.8.6
./configure
make
make install
默認安裝路徑爲/usr/local/Trolltech/Qt-4.8.6
./configure時出現下面問題時需要安裝Xlib
Basic XLib functionality test failed!
You might need to modify the include and library search paths by editing
QMAKE_INCDIR_X11 and QMAKE_LIBDIR_X11 in /home/zhu/Qt/qt-x11-opensource-src-4.5.2/mkspecs/linux-g++
apt-get install libxtst-dev libX11-dev libXext-dev
安裝QtCreator4.12
./qt-creator-opensource-linux-x86_64-4.12.0.run
配置編譯器
工具-》選項-》 Kits
Qt Version 添加/usr/local/Trolltech/Qt-4.8.6/bin/qmake
Kits-》桌面默認Qt version 選擇Qt 4.8.6
創建項目
編譯報錯/home/dhtc/test1/mainwindow.h:15: error: ‘nullptr’ was not declared in this scope
老版本不支持,修改 nullptr爲 NULL