Results 1 to 7 of 7

Thread: QListWidget refresh issue

  1. #1
    Join Date
    May 2009
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default QListWidget refresh issue

    Hi All,

    I am using QListWidget to show output ( e.g:- similar to output window you see in VS2005 IDE) .The problem I am facing is it's not updating accordingly,can anyone help me with this.
    I want it to add one item each second and show the updated result , but it just shows whole list after 5 second.

    Qt Code:
    1. void POCSleep::on_pushButton_clicked()
    2. {
    3. for(int i=0; i<5;i++)
    4. {
    5. ui.listWidget->update();
    6. mySleep(1); /* delay of one second*/
    7. displayMessage(QString("Number is: %1\n").arg( i+1));
    8. }
    9. }
    10. void POCSleep::displayMessage(QString qmsg)
    11. {
    12. ui.listWidget->addItem(qmsg);
    13. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QListWidget refresh issue

    Your sleep functions blocks the gui! Also that is not a good design. If you want it that way have a look at QCoreApplication::processEvents() and there is also an article on qt Quarterly about keepeing a gui app responsibly.

  3. #3
    Join Date
    May 2009
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListWidget refresh issue

    Ok. May be I shall explain the whole scenerio.
    I have one script (set of certain functions and commands) running at background ,It prints lot of information (till now I was using printf()) ,but now I want the same messages to be displayed in my DockWidget which contains QListWidget (for displaying messages).

    What would be the appropriate way of doing this?

  4. #4
    Join Date
    May 2009
    Posts
    62
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    2
    Thanked 16 Times in 15 Posts

    Default Re: QListWidget refresh issue

    Is the script running in another process? If so, use QProcess to start it and read the messages from there. You can connect to QIODevice::readyRead to get notified when the process has written data to stdout.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QListWidget refresh issue

    Quote Originally Posted by summer_of_69 View Post
    What would be the appropriate way of doing this?
    Use a worker thread for your "set of certain functions and commands" and use the signal slot mechanism to show the messages.

  6. #6
    Join Date
    May 2009
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: QListWidget refresh issue

    Quote Originally Posted by summer_of_69 View Post
    Qt Code:
    1. void POCSleep::on_pushButton_clicked()
    2. {
    3. for(int i=0; i<5;i++)
    4. {
    5. ui.listWidget->update();
    6. mySleep(1); /* delay of one second*/
    7. displayMessage(QString("Number is: %1\n").arg( i+1));
    8. }
    9. }
    10. void POCSleep::displayMessage(QString qmsg)
    11. {
    12. ui.listWidget->addItem(qmsg);
    13. }
    To copy to clipboard, switch view to plain text mode 
    Thanks for your valuable reply,this will definitely work.

    One thing I am unable to understand why worker thread is required for this?
    Can it be done in simpler way?? I have one class which take care of all script related functionalities I just need to call functions using my Dialog and display related error messages or any messages(which can be done in console using printf()) in my Qlistwidget.

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Wiki edits
    5

    Default Re: QListWidget refresh issue

    If you don't want that your GUI thread is blocked (this is the case when u use sleep) then you have to use your own treads or call processEvents().

    In Your case you also can use a QTimerLine or use QtConcurrent, depends on what you really want achieve. Your posted code seems to me like a "first testing". If you really only want to print 5 messages with a 1 second delay, then use QTimerLine.

Similar Threads

  1. QListWidget issue
    By febil in forum Qt Programming
    Replies: 2
    Last Post: 18th February 2009, 12:54
  2. Refresh Issue
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 14th August 2008, 19:34
  3. QListWidget painting issue
    By guilugi in forum Qt Programming
    Replies: 6
    Last Post: 16th April 2007, 18:06
  4. Mouse Drag selction Issue in QListWidget
    By vishal.chauhan in forum Qt Programming
    Replies: 5
    Last Post: 21st February 2007, 09:55
  5. Replies: 13
    Last Post: 15th December 2006, 12:52

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
  •  
Qt is a trademark of The Qt Company.