I am writing an application that interacts with the database. Since queries to the database are relatively heavy, I thought about moving the code into separate threads so as not to “freeze” the user interface.
In addition to queries to the database, this code also performs requests to the remote web server via the network. All anything, but QNetworkAccessManager does not provide methods that block the execution context at the time of sending requests and receiving answers to them. This feature leads to the need to organize a more complex code model. We'll have to combine asynchrony (work with the network) with multithreading (in fact, queries to the database).
The flow operation order:
- query to the database;
- based on the data received, the request to the network;
- based on the data retrieved, query to the database.
How to implement the combination of asynchrony with multithreading in the simplest way without using cumbersome constructions, such as inheritance from QThread and using its event loop?