Results 1 to 4 of 4

Thread: Can QListWidget's clear() be called from a slot connected with one of its signal?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2008
    Location
    Missouri City, TX, USA
    Posts
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Can QListWidget's clear() be called from a slot connected with one of its signal?

    Consider this code

    Qt Code:
    1. class SomeClass : public QWidget
    2. {
    3. public:
    4. SomeClass();
    5. ...
    6. private:
    7. QListWidget* _listWgt;
    8. };
    9.  
    10. SomeClass::SomeClass(QWidget* parent) : QWidget(parent)
    11. {
    12. _listWgt = new QListWidget(this);
    13. connect(_listWgt, SIGNAL(itemDoubleClicked(QListWidgetItem*), this, SLOT(onItemDoubleClicked(QListWidgetItem*));
    14. }
    15.  
    16. void SomeClass::onItemDoubleClicked(QListWidgetItem* item)
    17. {
    18. QString itemText = item->text();
    19. if(_listWgt){
    20. _listWgt->clear();
    21. }
    22. // Code to repopulate _listWgt with new list of items base on 'itemText'
    23. // follows.
    24.  
    25. }
    To copy to clipboard, switch view to plain text mode 

    My code is crashing in Qt as some timer event occurs on _listWgt that perhaps has information of _listWgt before it entered onItemDoubleClicked() slot, but after this slot is done, _listWgt doesn't reflect that state.

    I'm suspecting clear() as technically, it will try to delete the item on which the doubleClicked signal happened.

    Can anyone agree or confirm my suspicion?

    Thanks.
    Last edited by iunknwn; 30th September 2015 at 18:34.

Similar Threads

  1. Slot connected to a generic signal
    By Momergil in forum Qt Programming
    Replies: 5
    Last Post: 28th June 2014, 23:42
  2. Replies: 3
    Last Post: 29th September 2013, 12:46
  3. Replies: 11
    Last Post: 2nd February 2013, 15:39
  4. Replies: 2
    Last Post: 26th August 2011, 09:51
  5. Connected QTimer slot not being called
    By Polnareff in forum Qt Programming
    Replies: 4
    Last Post: 27th July 2010, 16:55

Tags for this Thread

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.