Detailed steps for MacOS to configure Clion's Qt environment (full version)

Table of contents

introduction:

process:

Install Qt in the terminal via brew:

The first error reported by the terminal when installing Qt: 

problem lies in:

Solve the problem:

Qt installed successfully: 

Obtain various information (path, version, time, installation credentials) of Qt installation through commands:

The qt version we installed:

The qt path we installed:

When we installed qt: 

Installation credentials:

Configure environment variables: 

Replace the path in the configuration environment variable with your Qt path:

Build completed: 


introduction:

Qt is a front-end language, because in the process of learning C language, we have written backgammon and ATM machine projects. Most of the students in our class use Windows computers, and after the core code of the project is completed, we usually need to Use a graphics library EasyX based on Visual Studio to design the graphical interface (GUI) of the project. But the EasyX graphics library is only for Windows and cannot be installed on MacOS, so my project progress has stagnated. I am looking for an alternative to EasyX on the Mac on the Internet. Qt is a replacement for EasyX graphics. In this article, I will describe how to build a Qt environment on a Mac computer.

process:

In the previous article:

MacOS configuration Clion detailed steps and mac terminal error problem solving (full version) https://blog.csdn.net/weixin_45571585/article/details/126977413?spm=1001.2014.3001.5502 has introduced C/C++ about Clion in detail Language programming environment construction, installation of homebrew plug-in, installation of gcc compiler through homebrew, and how to solve the problem of terminal error reporting during the installation process. Next, we continue to build the Qt language environment through brew:

Install Qt in the terminal via brew:

First, we open the terminal on the Mac computer and enter the command in the terminal:

brew install qt

After entering the command, the computer starts to download various parts of Qt in the terminal, as shown in the figure below, now we just need to wait:

The first error reported by the terminal when installing Qt: 

After the download is complete, the terminal error that may be encountered: 

problem lies in:

==> Running `brew cleanup qt`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

Solve the problem:

We enter this command in the terminal:

export HOMEBREW_NO_INSTALL_CLEANUP=TRUE

Terminal prompt:

pg.zeng@cengduodeMacBook-Pro ~ % export HOMEBREW_NO_INSTALL_CLEANUP=TRUE
pg.zeng@cengduodeMacBook-Pro ~ % brew install qt
fatal: not in a git directory
Warning: No remote 'origin' in /usr/local/Homebrew/Library/Taps/homebrew/homebrew-services, skipping update!
Warning: qt 6.3.1_4 is already installed and up-to-date.
To reinstall 6.3.1_4, run:
  brew reinstall qt

Qt installed successfully: 

Warning: qt 6.3.1_4 is already installed and up-to-date.
To reinstall 6.3.1_4, run:
  brew reinstall qt

Obtain various information (path, version, time, installation credentials) of Qt installation through commands:

Next, we enter this command in the terminal to check the information of the qt we installed:

brew info qt

After entering the command, the terminal displays:

The qt version we installed:

==> qt: stable 6.3.1 (bottled), HEAD
Cross-platform application and UI framework

The qt path we installed:

/usr/local/Cellar/qt/6.3.1_4 (12,891 files, 562.5MB) *

When we installed qt: 

  Poured from bottle on 2022-09-28 at 13:29:29

Installation credentials:

License: GFDL-1.3-only and GPL-2.0-only and GPL-3.0-only and LGPL-2.1-only and LGPL-3.0-only

Configure environment variables: 

In the previous step, we used the brew info qt command to display the relevant information of qt. To configure the qt environment variable, you need to use the path of qt. At this time, you should find out the path of qt in the terminal. For example, this is qt on my computer. The path I drew the red line:

Replace the path in the configuration environment variable with your Qt path:

At this time, we add commands after the qt path and enter:

export PATH="   你的qt安装路径    bin:$PATH"
export LDFLAGS="-L    你的qt安装路径     lib"
export CPPFLAGS="-I   你的qt安装路径  include"

For example, my qt path is:

/usr/local/Cellar/qt/6.3.1_4

All you need to do is copy your own qt installation path and replace the "your qt installation path" above, as follows:

export PATH="/usr/local/Cellar/qt/6.3.1_4/bin:$PATH""
export LDFLAGS="-L/usr/local/Cellar/qt/6.3.1_4/lib"
export CPPFLAGS="-I/usr/local/Cellar/qt/6.3.1_4/include"

Build completed: 

Ok, now that qt has been installed, we open Clion for verification. Here we create a new Clion project file:

The interface after creating the Qt file:

Configuration of the CmakeLists_.txt file:

cmake_minimum_required(VERSION 3.23)
project(untitled)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)


find_package(Qt6 COMPONENTS
        Core
        Gui
        Widgets
        REQUIRED)

add_executable(untitled main.cpp)
target_link_libraries(untitled
        Qt::Core
        Qt::Gui
        Qt::Widgets
        )

We click the green triangle in the red circle above to run the code given by default in the Qt file, as shown in the figure:

In the figure, we created a graphical interface with a length of 200 units and a width of 100 units, and output Hello World in the graphical interface.

So far, we have completed the construction of the Qt environment based on the Clion compiler on MacOS.

References:

MacOS+QT+CLion environment configuration_wsepom's blog-CSDN blog MacOS + QT + CLion environment configuration notes (QT6) https://blog.csdn.net/wsepom/article/details/122076768?ops_request_misc=%257B%2522request %255Fid%2522%253A%2522166426729816782395328095%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id =166426729816782395328095&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~ rank_v31_ecpm-1-122076768-null-null.142%5Ev50%5Enew_blog_pos_by_title,201%5Ev3%5Econtrol_1&utm_term=Mac%E9%85%8D%E7%BD%AEQt%EF%BC%88clion%EF%BC%89&spm=1018 .2226. 3001.4187 [Zero-based QT] [052] CLion perfectly builds a Qt development environment_Hand of Destiny Blog-CSDN Blog_clion qtWhat is CLion? CLion is a C language development environment developed by JetBrain. JetBrain is more famous for: Idea for developing Java, WebStorm for developing web pages, AndroidStudio for developing Android, JetBrain series is well-deserved the best IDE in the universe. CLion is developed in pure WIndows In fact, the functions may not be as complete and powerful as Visual Studio. After all, Visual Studio is Microsoft's own and has powerful... https://hellogoogle.blog.csdn.net/article/details/104238649?spm=1001.2101.3001.6650.4&utm_medium= distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-4-104238649-blog-122076768.t0_edu_mix&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-4- 104238649-blog-122076768.t0_edu_mix&utm_relevant_index=8 CLion2021.2 configure qt environment .https://blog.csdn.net/Dusk_Clouds/article/details/120791223?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-1-120791223-blog-104238649.pc_relevant_multi_platform_whitelistv6&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2~default~CTRLIST~Rate-1-120791223-blog-104238649.pc_relevant_multi_platform_whitelistv6

Guess you like

Origin blog.csdn.net/weixin_45571585/article/details/127074832