Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Cross-Platform Development with Qt 6 and Modern C++

You're reading from   Cross-Platform Development with Qt 6 and Modern C++ Design and build applications with modern graphical user interfaces without worrying about platform dependency

Arrow left icon
Product type Paperback
Published in Jun 2021
Publisher Packt
ISBN-13 9781800204584
Length 442 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Nibedit Dey Nibedit Dey
Author Profile Icon Nibedit Dey
Nibedit Dey
Arrow right icon
View More author details
Toc

Table of Contents (17) Chapters Close

Preface 1. Section 1: The Basics
2. Chapter 1: Introduction to Qt 6 FREE CHAPTER 3. Chapter 2: Introduction to Qt Creator 4. Chapter 3: GUI Design Using Qt Widgets 5. Chapter 4: Qt Quick and QML 6. Section 2: Cross-Platform Development
7. Chapter 5: Cross-Platform Development 8. Section 3: Advanced Programming, Debugging, and Deployment
9. Chapter 6: Signals and Slots 10. Chapter 7: Model View Programming 11. Chapter 8: Graphics and Animations 12. Chapter 9: Testing and Debugging 13. Chapter 10: Deploying Qt Applications 14. Chapter 11: Internationalization 15. Chapter 12: Performance Considerations 16. Other Books You May Enjoy

Building Qt 6 from source

If you want to build the framework and tools yourself or experiment with the latest unreleased code, then you can build Qt from the source code. If you're going to develop a specific Qt version from the source, then you can download the Qt 6 source code from the official releases link, as shown here: https://download.qt.io/official_releases/qt/6.0/.

If you are a commercial customer, then you can download the Source Packages from your Qt account portal. Platform-specific building instructions are discussed in the upcoming subsections.

You can also clone from the GitHub repository, and check out the desired branch. At the time of authoring this book, the Qt 6 branch remained inside the Qt 5 super module. You can clone the repository from the following link: git://code.qt.io/qt/qt5.git.

The qt5.git repository may get renamed to qt.git in the future for maintainability. Please refer to the QTQAINFRA-4200 Qt ticket. Detailed instructions on how to build Qt from Git can be found at the following link: https://wiki.qt.io/Building_Qt_6_from_Git.

Ensure that you install the latest versions of Git, Perl, and Python on your machine. Make sure there is a working C++ compiler before proceeding to the platform-specific instructions in the next section.

Installing Qt on Windows from source

To install Qt 6 on Windows from source code, follow these next steps:

  1. First of all, download the source code from Git or from the open source download link mentioned earlier. You will get a compressed file as qt-everywhere-src--%VERSION%.zip, where %VERSION% is the latest version (such as qt-everywhere-src-6.0.3.zip). Please note that suffixes such as -everywhere-src- may get removed in the future.
  2. Once you have downloaded the source archive, extract it to a desired directory—for example, C:\Qt6\src.
  3. In the next step, configure the build environment with a supported compiler and the required build tools.
  4. Then, add the respective installation directories of CMake, ninja, Perl, and Python to your PATH environment variable.
  5. The next step is to build the Qt library. To configure the Qt library for your machine type, run the configure.bat script in the source directory.
  6. In this step, build Qt by typing the following command in Command Prompt:
    >cmake --build . –parallel
  7. Next, enter the following command in Command Prompt to install Qt on your machine:
    >cmake --install .

Your Windows machine is now ready to use Qt.

To understand more about the configure options, visit the following link:

https://doc.qt.io/qt-6/configure-options.html

Detailed build instructions can be found at the following link:

https://doc.qt.io/qt-6/windows-building.html

Installing Qt on Linux from source

To build the source package on Linux distributions, run the following set of instructions on your terminal:

  1. First of all, download the source code from Git or from the open source download link mentioned earlier. You will get a compressed file as qt-everywhere-src--%VERSION%.tar.xz, where %VERSION% is the latest version (such as qt-everywhere-src-6.0.3.tar.xz). Please note that suffixes such as -everywhere-src- may get removed in the future.
  2. Once you have downloaded the source archive, uncompress the archive and unpack it to a desired directory—for example, /qt6, as illustrated in the following code snippet:
    $ cd /qt6
    $ tar xvf qt-everywhere-opensource-src-%VERSION%.tar.xz 
    $ cd /qt6/qt-everywhere-opensource-src-%VERSION%
  3. To configure the Qt library for your machine, run the ./configure script in the source directory, as illustrated in the following code snippet:
    $ ./configure
  4. To create the library and compile all the examples, tools, and tutorials, type the following commands:
    $ cmake --build . --parallel
    $ cmake --install .
  5. The next step is to set the environment variables. In .profile (if your shell is bash, ksh, zsh, or sh), add the following lines of code:
    PATH=/usr/local/Qt-%VERSION%/bin:$PATH
    export PATH

    In .login (if your shell is csh or tcsh), add the following line of code:

    setenv PATH /usr/local/Qt-%VERSION%/bin:$PATH

If you use a different shell, modify your environment variables accordingly. Qt is now ready to be used on your Linux machine.

Detailed building instructions for Linux/X11 can be found at the following link:

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

Installing Qt on macOS from source

Qt has a dependency on Xcode. To install Qt on your Mac, you will need Xcode installed on your machine. If you don't have Xcode installed on your machine, then you may proceed to install Xcode's Command Line Tools:

  1. To begin, type the following command on the terminal:
    $ xcode-select --install    
  2. If the terminal shows the following output, then your system is ready for the next steps:
    xcode-select: error: command line tools are already installed, use
    "Software Update" to install updates
  3. To build the source package, run the following set of instructions on your terminal:
    $ cd /qt6
    $ tar xvf qt-everywhere-opensource-src-%VERSION%.tar          
    $ cd /qt6/qt-everywhere-opensource-src-%VERSION%
  4. To configure the Qt library for your Mac, run the ./configure script in the source directory, as illustrated in the following code snippet:
    $ ./configure  
  5. To create a library, run the make command, as follows:
    $ make
  6. If -prefix is outside the build directory, then type the following lines to install the library:
    $ sudo make -j1 install
  7. The next step is to set the environment variables. In .profile (if your shell is bash), add the following lines of code:
    PATH=/usr/local/Qt-%VERSION%/bin:$PATH
    export PATH

    In .login (if your shell is csh or tcsh), add the following line of code:

    setenv PATH /usr/local/Qt-%VERSION%/bin:$PATH

Your machine is now ready for Qt programming.

Detailed building instructions for macOS can be found here:

https://doc.qt.io/qt-6/macos-building.html

In this section, we learned how to install Qt from source on your favorite platform. Now, let's summarize our learning.

You have been reading a chapter from
Cross-Platform Development with Qt 6 and Modern C++
Published in: Jun 2021
Publisher: Packt
ISBN-13: 9781800204584
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image