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.

Rotating the scene in OpenGL using the mouse (Qt)

To study the material of the article "Rotating a Scene in OpenGL Using the Mouse", you first need to study the material of this article.

The idea is very simple - intercept the mouse event, determine the mouse pointer movement speed, and based on this, calculate the scene rotation angle. Essentially the same as in the previous example, but the rotation is not done by a timer, but by a mouse event (mouse movement with a pressed button).

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.

Rotation of a scene in OpenGL (QT)

So, we already know how to initialize an OpenGL window in QT. (/podklyuchenie-opengl-v-qt/) Now let's learn how to rotate the scene. In short, to rotate the scene in OpenGL, you need to call the function void glRotated(GLdouble angle, GLdouble x, GLdouble y, GLdouble z). The angle parameter sets the rotation angle from the current position; x, y, z describe the rotation vector, in other words, they determine the direction of rotation. You can also change the position of the vector's origin.

Connecting OpenGL in QT

Let's consider an example of connecting the OpenGL graphics library to a QT project. I will try to provide the most accessible information for a quick start. Here we will only consider the example of connection and rendering of a simple scene. In the following notes, we will add camera rotation and so on.

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.