Host Installation Instructions for Qt

These are the instructions for installing the Qt library on your host machine so you can compile and test locally. The grading/reference environment virtual machines have their own (automated) installation.

We will be using the open source version of Qt. This is appropriate for academic use. Just note if you were to use Qt in a commercial application there are licensing issues to consider. The installer includes QtCreator, a nice enough IDE, if you are into that sort of thing. However, we will not be using some of the Qt tools, such as QTDesigner.

When doing the install be sure to do the step below involving modifications to your path. There is an example at the bottom of this page you can follow to make sure you have everything setup correctly. If you already have a working Qt >= 5.9.5 you can use that.

Download Link for All Platforms. Click on "Go Open Source" and "Accept". Then download and run the online installer for your system. You can skip the account creation step. Specify the directory where Qt should be installed and continue. Select the component Qt5.11.1. To save installation time and disk space expand that item and uncheck everything below that except the component for your OS: on Windows I recommend the MSVC 2015 32-bit component (yes, 2015, see note below); for macOS, make sure just "macOS" is checked; on Linux I assume you know what you are doing. Accept the license agreement and select install.

IMPORTANT: After the installation completes, add the path to the bin directory under the Qt installation path you selected during the install to your PATH environment variable. This will allow cmake to automatically find the library. You may have to logout/in for the change to take effect.

Note: There is always some confusion on Windows about which Qt configuration to use. Here are the details. Visual Studio (MSVC) is a 32-bit application, but it can generate 32 or 64-bit applications. Even if your Windows version is 64-bit (most likely) the default compiler is set to 32-bit. This is also the default chosen by CMake. The 32-bit code MSVC 2017 generates is ABI compatible with MSVC 2015, which is the 32-bit version of Qt in the installer, thus it works with MSVC in 32-bit mode. You can install the 64-bit MSVC 2017 version of Qt, but you need to force that compiler mode to be selected when you configure using cmake (select Visual Studio 15 2017 Win64 when prompted for a generator).

Test Example

  1. Create a working directory, e.g. qtexample, with subdirectories src and build.
  2. In the src directory create a C++ source file qtexample.cpp with the contents

     #include <QApplication>
     #include <QLabel>
    
     int main(int argc, char *argv[]){
       QApplication app(argc, argv);
    
       QLabel hello("Hello World!");
    
       hello.show();
       return app.exec();
    }
  3. In the src directory create a CMakeLists.txt file with the following contents

    cmake_minimum_required(VERSION 3.5)
    project(QtExample CXX)
    
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    find_package(Qt5Widgets REQUIRED)
    
    add_executable(qtexample qtexample.cpp)
    target_link_libraries(qtexample Qt5::Widgets)
  4. Run CMake using the src and buld directories respectively to configure the build for you chosen host development environment. On 64-bit Windows you need to specify the 64 bit VS when configuring with cmake.

  5. Build the program.

  6. Run the program and verify it shows a small window with the string "Hello World" in it.