Results 1 to 5 of 5

Thread: Show an indicator icon after a heavy process

  1. #1
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question 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:

    Qt Code:
    1. void myClass::heavyProcess(QString path)
    2. {
    3. setCursor(Qt::WaitCursor);
    4. QApplication::processEvents();
    5. // heavy process implementation
    6. setCursor(Qt::ArrowCursor);
    7. }
    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:

    Qt Code:
    1. void myClass::start_heavyProcess(QString path)
    2. {
    3. setCursor(Qt::WaitCursor);
    4. QApplication::processEvents();
    5. m_path = path; // I have added a class attribute to comunicate the value to heavyProcess() method. It is very dirty...
    6. QTimer::singleShot(0, this, SLOT(on_heavyProcess());
    7. }
    8.  
    9. void myClass::on_heavyProcess()
    10. {
    11. heavyProcess(m_path);
    12. }
    13.  
    14. void myClass::heavyProcess(QString path)
    15. {
    16. // heavy process implementation
    17. setCursor(Qt::ArrowCursor);
    18. }
    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Show an indicator icon after a heavy process

    Regarding passing the parameter

    Qt Code:
    1. void myClass::start_heavyProcess(QString path)
    2. {
    3. //....
    4.  
    5. QMetaObject::invokeMethod( this, "heavyProcess", Qt::QueuedConnection, Q_ARG( QString, path ) );
    6. }
    To copy to clipboard, switch view to plain text mode 

    No idea why your cursor doesn't change though
    Does it change if you do not execute the heavyProcess method?

    Cheers,
    _

  3. #3
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.
    Last edited by qt_developer; 11th September 2013 at 11:09.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Show an indicator icon after a heavy process

    Quote Originally Posted by qt_developer View Post
    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 View Post
    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,
    _

  5. #5
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up 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:

    Qt Code:
    1. void myClass::heavyProcess(QString path)
    2. {
    3. QApplication::setOverrideCursor(Qt::WaitCursor);
    4. QApplication::processEvents();
    5. // heavy process implementation
    6. QApplication::restoreOverrideCursor();
    7. }
    To copy to clipboard, switch view to plain text mode 

    Best regards.

Similar Threads

  1. Replies: 10
    Last Post: 20th April 2015, 22:24
  2. How to show two icon in QTreeView
    By Pardeep in forum Newbie
    Replies: 7
    Last Post: 11th February 2013, 13:52
  3. Replies: 4
    Last Post: 26th September 2011, 12:02
  4. QPushButton - Only show the Icon
    By graciano in forum Newbie
    Replies: 9
    Last Post: 19th September 2009, 21:15
  5. Show dialog application lunched as a process.
    By mourad in forum Qt Programming
    Replies: 0
    Last Post: 13th October 2008, 13:27

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.