Designing a cross-platform project
We want to display some visual gauges and chart widgets, so create a new Qt widgets Application called ch02-sysinfo
. As already discussed in Chapter 1, Get Your Qt Feet Wet, Qt Creator will generate some files for us: main.cpp
, MainWindow.h
, MainWindow.cpp
, and MainWindow.ui
.
Before diving into the C++ code, we must think about the software's architecture. This project will handle multiple desktop platforms. Thanks to the combination of C++ and Qt, most of the source code will be common to all targets. However, to retrieve both the CPU and memory usage from the OS (operating system), we will use some platform-specific code.
To successfully achieve this task, we will use two design patterns:
Strategy pattern: This is an interface that describes functionalities (for example, retrieve CPU usage), and specific behaviors (retrieve CPU usage on Windows/Mac OS/Linux) will be performed into subclasses that implement this interface.
Singleton pattern: This pattern guarantees...