Linux下安装Qt 6

在Linux平台下,安装Qt,与Windows基本一致,都是Qt在线图形化安装界面,但是有一点不同,需要前期环境准备。

安装必需环境

Linux 的 Qt 安装程序假定主机操作系统提供 C + + 编译器、调试器、 make 和其他开发工具。此外,构建图形化 Qt 应用程序需要安装 OpenGL 库和头文件。大多数 Linux 发行版在默认情况下不会安装所有这些软件,所以我们需要安装这些开发环境。

Debian/Ubuntu (apt-get):

sudo apt-get install build-essential libgl1-mesa-dev

Fedora/RHEL/CentOS (yum):

sudo yum groupinstall "C Development Tools and Libraries"
sudo yum install mesa-libGL-devel

下载Qt在线安装包

这里使用清华的镜像源

https://mirrors.tuna.tsinghua.edu.cn/qt/

这里我选择的下载路径是

https://mirrors.tuna.tsinghua.edu.cn/qt/archive/online_installers/4.5/

将qt-unified-linux-x64-4.5.2-online.run下载到本地,然后打开终端执行

./qt-unified-linux-x64-4.5.2-online.run

即可打开安装界面。之后的操作,与Windows无差异,不做过多阐述。

可能会遇到的问题

当安装完成之后,运行第一个helloworld程序,可能无法正常运行。会遇到如下错误:

CMake Warning at /usr/local/share/cmake-3.26/Modules/CMakeFindDependencyMacro.cmake:76 (find_package):
  Found package configuration file:                 
    /home/Leo/Qt/6.5.0/gcc_64/lib/cmake/Qt6Gui/Qt6GuiConfig.cmake                                             
  but it set Qt6Gui_FOUND to FALSE so package "Qt6Gui" is considered to be NOT FOUND.  Reason given by package:                                                                   
  Qt6Gui could not be found because dependency WrapOpenGL could not be found.                                 
  Configuring with --debug-find-pkg=WrapOpenGL might reveal details why the package was not found.                                                                                 
  Configuring with -DQT_DEBUG_FIND_PACKAGE=ON will print the values of some of the path variables that find_package uses to try and find the package.                                   

Call Stack (most recent call first):                                                                     /home/Leo/Qt/6.5.0/gcc_64/lib/cmake/Qt6/QtPublicDependencyHelpers.cmake:111 (find_dependency)               
/home/Leo/Qt/6.5.0/gcc_64/lib/cmake/Qt6Widgets/Qt6WidgetsDependencies.cmake:39 (_qt_internal_find_qt_dependencies)                                                                                               /home/Leo/Qt/6.5.0/gcc_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake:40 (include)                          
/home/Leo/Qt/6.5.0/gcc_64/lib/cmake/Qt6/Qt6Config.cmake:157 (find_package)                                  
  CMakeLists.txt:15 (find_package)                                                                       
CMake Warning at /home/Leo/Qt/6.5.0/gcc_64/lib/cmake/Qt6/Qt6Config.cmake:157 (find_package):
  Found package configuration file:                 
    /home/Leo/Qt/6.5.0/gcc_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake                                   
   
  but it set Qt6Widgets_FOUND to FALSE so package "Qt6Widgets" is considered to be NOT FOUND.  Reason given by package:                                    
  Qt6Widgets could not be found because dependency Qt6Gui could not be found.                                 
                                                                                                              
  Configuring with --debug-find-pkg=Qt6Gui might reveal details why the  package was not found.                                                                                 
  Configuring with -DQT_DEBUG_FIND_PACKAGE=ON will print the values of some                                   
  of the path variables that find_package uses to try and find the package.                           
Call Stack (most recent call first):                                                                     
  CMakeLists.txt:15 (find_package)                                                                            
                                                     
CMake Error at CMakeLists.txt:15 (find_package):
  Found package configuration file:                                                                     
    /home/Leo/Qt/6.5.0/gcc_64/lib/cmake/Qt6/Qt6Config.cmake                                                   

  but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT FOUND.  Reason given by package:                                                                                                                    
  Failed to find required Qt component "Widgets".                                                       
  Expected Config file at                                                                               "/home/Leo/Qt/6.5.0/gcc_64/lib/cmake/Qt6Widgets/Qt6WidgetsConfig.cmake"                                     
  exists                                                                                                      

  Configuring with --debug-find-pkg=Qt6Widgets might reveal details why the package was not found.                                                                                 
  Configuring with -DQT_DEBUG_FIND_PACKAGE=ON will print the values of some of the path variables that find_package uses to try and find the package.

原因是因为没有按照第一步安装环境,缺失libgl1-mesa-dev

使用sudo apt install libgl1-mesa-dev安装之后,即可正常运行。

https://doc.qt.io/qt-6/linux.html

你可能感兴趣的:(linux,qt,运维)