Skip to content
hpepper edited this page Apr 24, 2022 · 13 revisions

Qt quick notes

Introduction

References

Installation

Installing Qt 5

  1. Go to https://www.qt.io/download
  2. Click on: 'Go open source'
  3. Click: 'Download the Qt Online Installer' (a fair bit down)
  4. click on 'Download'
  5. chmod +x ~/Downloads/qt-unified-linux-x64-4.3.0-1-online.run
  6. ~/Downloads/qt-unified-linux-x64-4.3.0-1-online.run

Upgrade to Qt 6

Notes

Source: https://forum.qt.io/topic/47930/main-window-class-vs-widget-class/4 When working with widgets the practical choice is between QMainWindow, QWidget and QDialog.

The QDialog choice is obvious for, well, dialogs. It includes and exec() method to start a local loop and has methods to standard dialog actions - accept and reject (ok/cancel).

QMainWindow has features for building a main app experience. It has built-in specialized layout for housing status and tool bars. It also has a powerful docking capabilities for creating dynamic app layouts using QDockWidgets.

QWidget is the generic choice when you don't need any of the above capabilities. This is often true for various tool windows, widgets meant to be embedded in the QDockWidgets and all the windows types that don't have rich widget-based UI eg. games or visualization windows.

Depending on an app type there's usually a single QMainWidget used for the main app window, several smaller QWidget based windows as docks, visualization and tool windows and occasional QDialogs for "talking" to the user.

Tools

  • qtdialog
  • qmake

qmake

  • /path/to/qt/installation/5.7/gcc_64/bin/qmake -makefile -o Makefile /path/to/sysinfoproject/ch02-sysinfo.pro

  • make

  • the moc_*.cpp file) containing everything Qt needs to properly handle your signals and slots.

qmake project file .pro

  • '#' : comment line
  • = : This operator sets the variable to the value.
  • += : This operator adds the value to a list of values.
  • -= : This operator removes the value from the list.
  • *= : This operator adds the value to the list only if it is not already present.
  • ~= : This operator replaces any values that match a regular expression with the specified value, DEFINE ~= s/DEBUG_FLAG/debug .
  • QT : This is a list of the Qt modules used in the project. In the platform-specific Makefile, each of the values will include the module headers and the corresponding library link.
  • CONFIG : This is a list of configuration options for the project. Here, we configure the support of C++14 in the Makefile.
  • TARGET : This is the name of the target output file.
  • TEMPLATE : This is the project template used when generating the Makefile.app tells qmake to generate a Makefile targeted for a binary. If you are building a library, use the lib value.
  • macx/linux/windows : for that OS only
    • windows {
      • SOURCES += SysInfoWindowsImpl.cpp
      • HEADERS += SysInfoWindowsImpl.h
    • }
    • You can even have else if/else statements:
windows|unix {
  SOURCES += SysInfoWindowsAndLinux.cpp
} else:macx {
  SOURCES += SysInfoMacImpl.cpp
} else {
  SOURCES += UltimateGenericSources.cpp
}
  • message($$COMPILE_MSG linux) : display string, during compilation.
  • error(string) : This function displays the string and exits the compilation immediately.
  • exists(filename) : This function tests the existence of the filename . qmake also provides the ! operator, which means you can write !exist(myfile)
  • include(filename) : This function includes the content of another .pro file.

qmake cli

  • qmake -makefile -o Makefile project.pro
    • -makefile: generate a 'Makefile' based on your project.pro file.

Model View Controller

My personal take on how to decide if it goes in view on controller:

If the same code would have to be implemented(the same way) between two views(desktop vs mobile) then it is probably controller code.

  • The Model manages the data. It is responsible for requesting for the data and updating it.
  • The View displays the data to the user.
  • The Controller interacts with both the Model and the View.
    • It is responsible for feeding the View with the correct data and sending commands to the Model based on the user interaction received from the View.

Code Documentation

qdoc: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qdoc': No such file or directory

A: You have to run the local install instead of the system install ~/Qt/5.11.2/gcc_64/bin/qdoc project.qdocconf

QTest

Area

QMainWindow

Layout

QGridLayout

Troubleshooting

invalid use of incomplete type 'class QStatusBar'

See: https://forum.qt.io/topic/58057/solved-invalid-use-of-incomplete-type-class-ui-mainwindow/2

Was missing: #include

Clone this wiki locally