Results 1 to 2 of 2

Thread: problem with QListWidget::currentRowChanged signal

  1. #1
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default problem with QListWidget::currentRowChanged signal

    Hello,
    I am experiencing a problem with the QListWidget::currentRowChanged signal when I remove the first element from a QListWidget. Please see my TestWidget class:

    Qt Code:
    1. // TestWidget.h
    2. //
    3. #include <QWidget>
    4. #include <QMessageBox>
    5. #include <QListWidget>
    6. #include <QVBoxLayout>
    7. #include <QPushButton>
    8.  
    9. class TestWidget: public QWidget
    10. {
    11. Q_OBJECT
    12. public:
    13. TestWidget::TestWidget(QWidget* parent = 0):
    14. QWidget(parent)
    15. {
    16. lst = new QListWidget();
    17. lst->addItem("first");
    18. lst->addItem("second");
    19. connect(lst, SIGNAL(currentRowChanged(int)),
    20. this, SLOT(onRowChanged(int)));
    21.  
    22. QPushButton* btn = new QPushButton("Remove first row");
    23. connect(btn, SIGNAL(clicked(bool)),
    24. this, SLOT(onBtnClicked(bool)));
    25.  
    26. l->addWidget(lst);
    27. l->addWidget(btn);
    28.  
    29. setLayout(l);
    30. }
    31.  
    32. private slots:
    33. void onRowChanged(int);
    34. void onBtnClicked(bool);
    35.  
    36. private:
    37. };
    38.  
    39. inline void TestWidget::onBtnClicked(bool)
    40. {
    41. delete lst->takeItem(0); // triggers rowChanged
    42.  
    43. // current row number == 0 ... Correct
    44. QMessageBox::information(this, "Debug",
    45. QString("onBtnClicked: current row number: %1")
    46. .arg(lst->currentRow()));
    47. }
    48.  
    49. inline void TestWidget::onRowChanged(int i)
    50. {
    51. // new row number == 1 ... Why?
    52. QMessageBox::information(this, "Debug",
    53. QString("onRowChanged: new row number: %1").arg(i));
    54. }
    To copy to clipboard, switch view to plain text mode 

    The program starts and current row is 0. Then I click the button to remove the first row and rowChanged is triggered with a value of 1. Why? Back from the rowChanged event and the current row is 0 (correct)

    Any clues?

    Qt 4.6.3
    Visual Studio 2008 SP1

  2. #2
    Join Date
    Mar 2014
    Posts
    18
    Thanks
    3
    Qt products
    Qt3 Qt4 Qt/Embedded

    Default Re: problem with QListWidget::currentRowChanged signal

    Hi,

    i would suggest, that by deleting of row 0, row 1 changes to row 0.
    And because of this renumbering you get the trigger, that row 1 has changed.

    Just a suggestion

Similar Threads

  1. No such signal QListWidget::itemClicked
    By ouekah in forum Newbie
    Replies: 1
    Last Post: 22nd February 2010, 14:48
  2. QListWidget SIGNAL Problem
    By skuda in forum Qt Programming
    Replies: 19
    Last Post: 28th October 2009, 14:42
  3. QListWidget signal problem
    By rishid in forum Qt Programming
    Replies: 6
    Last Post: 18th January 2008, 20:43
  4. QListWidget clicked signal
    By asieriko in forum Qt Programming
    Replies: 12
    Last Post: 10th August 2007, 15:37
  5. QListWidget::currentRowChanged() for QListView
    By Lykurg in forum Qt Programming
    Replies: 1
    Last Post: 13th March 2007, 15:27

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.