Results 1 to 5 of 5

Thread: QListView force redraw.

  1. #1
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QListView force redraw.

    Hi there, first post to the forums. Hope someone can help me.

    I have a list view which is populated by any of a number of background threads (mutex locked of course ;-). The problem I have is that the list view only redraws with the new rows when I resize it (it's in a docking window).

    I guess I need to emit a signal to get it to redraw but I've tried every signal I can find and still no joy. Code sample follows. What am I doing wrong. I guess I need to get the main event loop to fire but how do I send an appropriate event from another thread?

    Qt Code:
    1. class MessageList : public QListWidget
    2. {
    3. Q_OBJECT
    4. public:
    5. MessageList(QWidget* pW) : QListWidget(pW) {}
    6.  
    7. void logMessage(const std::string& sMessage) {
    8. boost::mutex::scoped_lock scoped_lock(m_oMessageListMutex);
    9. QListWidgetItem *item = new QListWidgetItem(sMessage.c_str(), this);
    10. setCurrentItem (item);
    11. update();
    12. emit itemChanged(item);
    13. emit itemActivated (item);
    14. emit itemClicked (item);
    15. emit itemDoubleClicked (item);
    16. emit itemEntered (item);
    17. emit itemPressed (item);
    18. }
    19.  
    20. protected:
    21. boost::mutex m_oMessageListMutex;
    22. };
    To copy to clipboard, switch view to plain text mode 

    Many thanks
    Dave

  2. #2
    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: QListView force redraw.

    Quote Originally Posted by Dave Stewart View Post
    I have a list view which is populated by any of a number of background threads (mutex locked of course ;-).
    That won't work. Mutex or no mutex... You can't update the list from within external threads. Instead emit a signal from other threads that will be connected to a custom slot in the view that will add the items. You won't need any special treatment then.

  3. #3
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView force redraw.

    Quote Originally Posted by wysota View Post
    That won't work. Mutex or no mutex... You can't update the list from within external threads. Instead emit a signal from other threads that will be connected to a custom slot in the view that will add the items. You won't need any special treatment then.
    Hi wysota, thanks for the reply. Your suggestion seems straight forward enough but I can't get it to work.

    I've defined the following in MainWindow.h in class MainWindow

    Qt Code:
    1. void logMessage(const std::string& sMessage) {
    2. boost::mutex::scoped_lock scoped_lock(m_oMessageListMutex);
    3. emit logMessageSignal(QString(sMessage.c_str()));
    4. }
    5.  
    6. signals:
    7. void logMessageSignal(QString& sMessage);
    8.  
    9. public slots:
    10. void messageReceived(QString& sMessage) {
    11. QListWidgetItem *item = new QListWidgetItem(sMessage, messagesListWidget);
    12. }
    To copy to clipboard, switch view to plain text mode 

    logMessage() is called from the worker threads.

    In MainWindow.cpp I have connected as follows (called from the main thread):

    Qt Code:
    1. connect(this, SIGNAL(logMessageSignal(QString& sMessage)), this, SLOT(messageReceived(QString& sMessage)));
    To copy to clipboard, switch view to plain text mode 

    I get a runtime error:

    Object::connect: No such signal MainWindow::logMessageSignal(QString&sMessage)
    Object::connect: (sender name: 'MainWindow')
    Object::connect: (receiver name: 'MainWindow')

    cheers
    Dave

  4. #4
    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: QListView force redraw.

    Don't pass parameter names into signal and slot signatures.

    http://www.qtcentre.org/forum/faq.ph...lot_with_names

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

    Dave Stewart (19th December 2007)

  6. #5
    Join Date
    Dec 2007
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView force redraw.

    Quote Originally Posted by wysota View Post
    Don't pass parameter names into signal and slot signatures.

    http://www.qtcentre.org/forum/faq.ph...lot_with_names
    Thanks for that. I'll check the FAQS first in future.

    Cheers
    Dave

Similar Threads

  1. QListView word wrap
    By serega in forum Qt Programming
    Replies: 17
    Last Post: 30th August 2007, 03:13
  2. nmake problems while building mysql driver
    By MarkoSan in forum Installation and Deployment
    Replies: 27
    Last Post: 25th May 2007, 12:57
  3. Force redraw of QSimpleRichText when QStyleSheet changes
    By SHesselbarth in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2006, 16:10
  4. QT4 beginner Fatal Error
    By Remyfr in forum Installation and Deployment
    Replies: 3
    Last Post: 11th March 2006, 01:48

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.