In my loadDatabase function, I have clearly set the status to display the message "loading coverage database..." before setOverrideCursor(Qt::WaitCursor), but the status bar is only displaying the message after restoreOverrideCursor() is called. I have tried various ways to display the message before setOverrideCursor(Qt::WaitCursor), but I'm unsure of the reason behind this behavior.
void loadDatabase(const QString &name) {
//setting statusBar's message
statusBar()->showMessage("loading coverage database...");
QApplication::setOverrideCursor(Qt::WaitCursor);
//loading the database and setting up the GUI are CPU-intensive operations.
m_logger_widget->clear();
m_logger_widget->info("opening database %s", name.toStdString().data());
auto coverage_database = new CoverageDatabase(name, m_logger_widget);
m_instance_view->setModel(coverage_database->getInstanceModel());
QApplication::restoreOverrideCursor();
}
I hope to identify the reason why "loading coverage database..." is not displayed and to have it shown before setting the WaitCursor.
Your
loadDatabase()function runs in the main GUI thread, it blocks all further GUI updates until it completes.One possibility is to call the function
QCoreApplication::processEvents()after you have set the status message.https://doc.qt.io/qt-6/qcoreapplication.html#processEvents
However, I would outsource the loading to an asynchronous task/thread. This way you also get the possibility to abort the loading process.