Results 1 to 20 of 20

Thread: change cursor icon while program is busy

  1. #1
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default change cursor icon while program is busy

    Hello!

    I've got application which runs other application in new thread by clicking on a button:

    Qt Code:
    1. QProcess *proc;
    2. proc = new QProcess( this );
    3. proc->startDetached("/home/program");
    To copy to clipboard, switch view to plain text mode 

    is there any simple way to change cursor icon (for example to clock or anything else) while program is loading? Because sometimes it is loading quite long and I don't know if i clicked button or not.

    thanks in advance
    best regards
    Tomasz

  2. #2
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: change cursor icon while program is busy

    I assume you have already subclassed QCursor.

    Connect the program-loading code to a slot in your custom cursor object that updates the cursor's pixmap. Then you just emit the appropriate signal when you start or finish loading.

  3. The following user says thank you to Urthas for this useful post:

    Tomasz (30th August 2010)

  4. #3
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change cursor icon while program is busy

    I think some example code will be very useful in this case. Still have no idea how to get down to it.

    thanks in advance
    best regards
    Tomasz

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: change cursor icon while program is busy


  6. The following user says thank you to ChrisW67 for this useful post:

    Tomasz (31st August 2010)

  7. #5
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change cursor icon while program is busy

    Can I make it wait with QApplication::restoreOverrideCursor() until my application is fully loaded? Because now cursor changes for a moment and application is still loading (code in first message).

    thanks in advance
    best reagards
    Tomsz

  8. #6
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: change cursor icon while program is busy

    Before you call proc->startDetached(), connect proc's started() signal to a slot that calls QApplication::setOverrideCursor(), and connect proc's finished() signal to a slot that calls QApplication::restoreOverrideCursor()?

  9. The following user says thank you to Urthas for this useful post:

    Tomasz (1st September 2010)

  10. #7
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change cursor icon while program is busy

    I've done it that way:

    Qt Code:
    1. void MainWindow::runMyApp(QString parameter)
    2. {
    3. QProcess *proc;
    4.  
    5. proc = new QProcess( this );
    6.  
    7. connect(proc, SIGNAL(started()), this, SLOT(appIsBusy()));
    8. connect(proc, SIGNAL(finished(int)),this, SLOT(appIsFree()));
    9.  
    10. proc->startDetached("/myapp", QStringList() << parameter);
    11.  
    12. delete proc;
    13. }
    To copy to clipboard, switch view to plain text mode 

    But with no effect. Any other idea? Or maybe I should do it in different way?

    thanks in advance
    best regards
    Tomasz

  11. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: change cursor icon while program is busy

    This code doesn't make any sense. You connect some signals and immediately delete the object... startDetached() is not a blocking call.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. The following user says thank you to wysota for this useful post:

    Tomasz (20th September 2010)

  13. #9
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change cursor icon while program is busy

    As I thought it's senseless. So is it possible to make what I want without deleting QProcess object? Earlier I was just changing icon for some time and then restoring it but sometimes app was loading longer or faster...

    thanks in advance
    best regards
    Tomasz

  14. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: change cursor icon while program is busy

    Create a QProcess object and set it up with the data you need. Connect the started() signal to some slot of yours. Optionally connect the finished() signal with a deleteLater() slot to destroy the object once the child process exits. Change the cursor, start the process. In the slot connected to the started() signal restore the cursor.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #11
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change cursor icon while program is busy

    So I've done something like this:

    Qt Code:
    1. void MainWindow::runMyApp(QString parameter)
    2. {
    3. QProcess *proc;
    4.  
    5. proc = new QProcess( this );
    6.  
    7. QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    8. connect(proc, SIGNAL(started()), this, SLOT(appIsLoaded()));
    9.  
    10. proc->startDetached("/myapp", QStringList() << parameter);
    11.  
    12. delete proc;
    13. }
    To copy to clipboard, switch view to plain text mode 

    My cursor is changing, but I can't restore it back. I know that @wysota said I shouldn't delete my process byt I'm using proc->startDetached() because if I use proc->start my parent application is closing when I'm closing child application. If I use proc->startDetached() in child application cursor is normal but on parent application I still have 'WaitCursor'. Any suggestions? How can I do it?

    thanks in advance
    best regards
    Tomasz

  16. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: change cursor icon while program is busy

    startDetached() does not wait until the process actually gets started. By deleting the object immediately, you don't have a chance to catch any of its signals. You should connect the started() or finished() signal to the deleteLater() slot and you'll be fine. If your parent is closing when the child closes than it probably crashes and not closes and there is something wrong with your code.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  17. #13
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change cursor icon while program is busy

    So, I've got something like this:

    Qt Code:
    1. void MainWindow::runMyApp(QString parameter)
    2. {
    3. QProcess *proc;
    4.  
    5. proc = new QProcess( this );
    6.  
    7. QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
    8. connect(proc, SIGNAL(finished()), this, SLOT(appIsLoaded()));
    9. connect(proc, SIGNAL(finished(int)),this, SLOT(deleteLater()));
    10.  
    11. proc->start("/myapp", QStringList() << parameter);
    12. }
    To copy to clipboard, switch view to plain text mode 

    And console gives:

    Qt Code:
    1. Object::connect: No such signal QProcess::finished()
    2. Object::connect: (receiver name: 'MainWindow')
    3. *** glibc detected *** /qt/test: free(): invalid pointer: 0xbef3db44 ***
    To copy to clipboard, switch view to plain text mode 

    Parent application (test) is closing when I'm closing child application. But 'ps' command says that 'test' is still working... I've tried to run 'clean' application that is doing nothing to be sure everything is OK with child application, and same thing happens.

    Any ideas?

    thanks in advance
    best regards
    Tomasz


    -------------------------------------------
    Edit:
    Of course in first connect should be finished(int) then console gives only:

    Qt Code:
    1. *** glibc detected *** /qt/test: free(): invalid pointer: 0xbee37b44 ***
    To copy to clipboard, switch view to plain text mode 
    Last edited by Tomasz; 24th September 2010 at 10:37.

  18. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: change cursor icon while program is busy

    You are probably deleting the same object twice somewhere.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  19. #15
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change cursor icon while program is busy

    Ok. Maybe this will be stupid question, but I need to ask - when child process is exiting what is happening with the pointer and all reserved memory for that process? You said that I'm probably deleting same object twice, so I removed one line to see what will happen:

    Qt Code:
    1. connect(proc, SIGNAL(finished(int)),this, SLOT(deleteLater()));
    To copy to clipboard, switch view to plain text mode 

    And now it seems everything looks fine but I don't know if I'm doing some mess in memory. So I need to know Is everything being delete when I'm closing child application.

    thanks in advance
    best regards
    Tomasz

  20. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: change cursor icon while program is busy

    Quote Originally Posted by Tomasz View Post
    Ok. Maybe this will be stupid question, but I need to ask - when child process is exiting what is happening with the pointer and all reserved memory for that process?
    You mean the QProcess object? Nothing is happening to it. It's not deleted automatically if that's what you're asking.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  21. #17
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change cursor icon while program is busy

    So I have no idea why my app is crashing if I try to delete my QProcess object:

    Qt Code:
    1. connect(proc, SIGNAL(finished(int)), this, SLOT(appIsLoaded()));
    2. connect(proc, SIGNAL(finished(int)), this, SLOT(deleteLater())); //without it works fine, no errors
    3. proc->start("/myapp", QStringList() << parameter);
    To copy to clipboard, switch view to plain text mode 

    It happens when I run process by start() If I use startDetached() I can delete QProcess object without any error... I've checked if I'm deleting something twice, and I'm not. QProcess object is the only thing I'm deleting.

    thanks in advance
    best regards
    Tomasz

  22. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: change cursor icon while program is busy

    Maybe you are doing it in appIsLoaded()? Anyway, you can reuse the object again if you need to spawn the process again so you don't have to create and delete it every time.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  23. The following user says thank you to wysota for this useful post:

    Tomasz (24th September 2010)

  24. #19
    Join Date
    Jul 2010
    Location
    Poland
    Posts
    184
    Thanks
    70
    Thanked 7 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: change cursor icon while program is busy

    appIsLoaded() only restores cursor nothing more. But I's good idea to reuse that pointer. I'll declare it in header file and use every time I need. Should I clean It or something after every use?

    But I'm still curious about why it crashes...

    thanks in advance
    best regards
    Tomasz

  25. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: change cursor icon while program is busy

    No, you don't have to do anything with it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  26. The following user says thank you to wysota for this useful post:

    Tomasz (24th September 2010)

Similar Threads

  1. Replies: 1
    Last Post: 19th July 2010, 11:43
  2. Constant busy cursor when application is run
    By b1 in forum Qt for Embedded and Mobile
    Replies: 2
    Last Post: 10th January 2010, 21:30
  3. QPushButton icon & dialog cursor
    By hulud in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 5th November 2009, 15:08
  4. Replies: 2
    Last Post: 12th October 2008, 14:42
  5. change cursor
    By nicky in forum Qt Programming
    Replies: 2
    Last Post: 31st January 2007, 11:07

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.