qt_developer
10th September 2013, 19:09
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);
QApplication::processEvents();
// heavy process implementation
setCursor(Qt::ArrowCursor);
}
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);
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);
}
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.
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);
QApplication::processEvents();
// heavy process implementation
setCursor(Qt::ArrowCursor);
}
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);
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);
}
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.