Show an indicator icon after a heavy process
Hi all,
I want to show an indicator icon before a heavy process. I've used the next code:
Code:
void myClass
::heavyProcess(QString path
) {
setCursor(Qt::WaitCursor);
// 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:
Code:
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);
}
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.
Re: Show an indicator icon after a heavy process
Regarding passing the parameter
Code:
void myClass
::start_heavyProcess(QString path
) {
//....
QMetaObject::invokeMethod( this,
"heavyProcess", Qt
::QueuedConnection, Q_ARG
( QString, path
) );
}
No idea why your cursor doesn't change though :(
Does it change if you do not execute the heavyProcess method?
Cheers,
_
Re: Show an indicator icon after a heavy process
Hi anda_skoa,
I've used QMetaObject::invokeMethod() instead of QTimer::singleShot(). Is it possible to set a time delay like in QTimer::singleShot()?
Yes, if I do not execute the heavyProcess method, the cursor changes.
Best regards.
Re: Show an indicator icon after a heavy process
Quote:
Originally Posted by
qt_developer
I've used QMetaObject::invokeMethod() instead of QTimer::singleShot(). Is it possible to set a time delay like in QTimer::singleShot()?
No, it only delays (that is what Qt::QueuedConnection does) the invocation, i.e. like QTimer::singleShot() with 0 timeout.
If you need a different timeout, you will need QTimer.
Quote:
Originally Posted by
qt_developer
Yes, if I do not execute the heavyProcess method, the cursor changes.
Interesting. Your attempt of delaying the blocking processing looks correct to me.
Cheers,
_
Re: Show an indicator icon after a heavy process [SOLVED]
Hi,
I've solved the problem. I've changed the the code in my first attempt and works properly now:
Code:
void myClass
::heavyProcess(QString path
) {
// heavy process implementation
}
Best regards.