Hi all,
I want to show an indicator icon before a heavy process. I've used the next code:
void myClass
::heavyProcess(QString path
) {
setCursor(Qt::WaitCursor);
// heavy process implementation
setCursor(Qt::ArrowCursor);
}
void myClass::heavyProcess(QString path)
{
setCursor(Qt::WaitCursor);
QApplication::processEvents();
// heavy process implementation
setCursor(Qt::ArrowCursor);
}
To copy to clipboard, switch view to plain text mode
But the indicator icon does not show. I think that the reason is because the code is synchronous. Therefore I have used this other implementation:
void myClass
::start_heavyProcess(QString path
) {
setCursor(Qt::WaitCursor);
m_path = path; // I have added a class attribute to comunicate the value to heavyProcess() method. It is very dirty...
QTimer::singleShot(0,
this,
SLOT(on_heavyProcess
());
}
void myClass::on_heavyProcess()
{
heavyProcess(m_path);
}
void myClass
::heavyProcess(QString path
) {
// heavy process implementation
setCursor(Qt::ArrowCursor);
}
void myClass::start_heavyProcess(QString path)
{
setCursor(Qt::WaitCursor);
QApplication::processEvents();
m_path = path; // I have added a class attribute to comunicate the value to heavyProcess() method. It is very dirty...
QTimer::singleShot(0, this, SLOT(on_heavyProcess());
}
void myClass::on_heavyProcess()
{
heavyProcess(m_path);
}
void myClass::heavyProcess(QString path)
{
// heavy process implementation
setCursor(Qt::ArrowCursor);
}
To copy to clipboard, switch view to plain text mode
But the indicator icon does not show all the times and the way to pass parameter to the heavyProcess() method is very bad.
How can I improve the code?
Best regards.
Bookmarks