Sleep in Qt

Somehow got very distracted from Qt. And then the other day had to come back =) Spent a long time remembering how I used to implement delays, or sleep in Qt (yes, yes, yes, it's bad, etc., but sometimes you really need it, especially if you need to turn in a lab to make others stop bothering you.)

Example of a trivial implementation:

Usage of QwtPlotSpectrogram

Previously, we learned to use the QwtPlotSpectrocurve component (here). Qwt provides an alternative component that is more convenient for visualizing analytical functions. In this note, we will learn how to use QwtPlotSpectrogram.

Configuration of Qt project

An application written in cross-platform Qt. (Except for tricky third-party libraries, but that's the exception). However, to run the application on different platforms, you often still need to properly configure the Qt project. (The project is configured in the .pro file).

Using QwtPlotSpectroCurve

Using QwtPlotSpectroCurve (first familiarize yourself with QwtPlotCurve here) you can display information that requires representation in three dimensions; create pseudo 3D graphs on a two-dimensional plane. The third dimension will be conveyed through color gradients - these graphs are called spectrograms. Unlike the QwtPlotSpectrogram component, you control each point on the curve, rather than intervals. The QwtPlotSpectroCurve component is less functional but more logical for graph plotting.

Using a Timer in Qt

For using the timer in Qt, the class QTimer is intended. First, you need to set the time after which it will trigger. You also need to define a slot that will handle the signal emitted when the timer overflows. Thus, a mandatory condition for using QTimer is the ability to use signals and slots, which means that the class that uses the timer must be a descendant of QObject. Let's create a simple clock as an example.

Including QwtPlotGrid in Qwt (QwtPlot)

For easier perception of information, for reading charts, you can enable the grid. This is done using the QwtPlotGrid class. Everything is as usual: the object needs to be created, configured, and attached to the qwtplot.

Building histograms (QT)

Building histograms in QT is done using Qwt. The logic of building them is similar to building graphs. (First, I suggest reading this.) Let's consider a simple example of building a histogram using QwtPlotHistogram.

Building graphs (QT)

Unfortunately, in QT there is no convenient component TChart (from Borland, for Delphi/Builder). But there is a good alternative - Qwt. There should be no problems with adding graphs and histograms, but sometimes (depending on the task) there may be difficulties with bubbles. But not now. Let's start with regular graphs.

About Random Numbers

Very often, when modeling physical processes, it is necessary to implement a random number generator (or simply "random"). Let's start with the basics. In fact, there is no perfect, "correct" random number generator. To some extent, this task can be performed by a girl, as female logic is also a random generator (and a pretty good one). But we are interested in implementing it in QT.