0

My application reads mysql database and draws table based on mysql queries. I want to use progressbar but i can't because QSqlDatabase processes freeze my main window.

I read somewhere, i should separate threads of gui and mysql processes and use interprocess communication, but can't find any examples. What is the best way to transmit mysql query between threads?

r_spb
  • 75
  • 1
  • 14

1 Answers1

1

There are 2 ways to prevent your GUI from freezing:

  • Offloading timely computations to a worker thread and communicating with the main GUI thread by means of signals.

  • Asking your GUI thread to process some of its pending messages in the event loop.

I recommend to go for the second option since it is quick and usually solves these kinds of problems. But remember that it is not the clean way of doing things and one should squeeze the demanding calculations off the main GUI thread.

The second solution involves putting a single function call somewhere in your query consuming loop. The general schema would be:

While(query.next()){
    ...
    QApplication::processEvents();
    ...
}
reza
  • 90
  • 1
  • 14