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:
Code:
// TestWidget.h
//
#include <QWidget>
#include <QMessageBox>
#include <QListWidget>
#include <QVBoxLayout>
#include <QPushButton>
{
Q_OBJECT
public:
TestWidget
::TestWidget(QWidget* parent
= 0): {
lst->addItem("first");
lst->addItem("second");
connect(lst, SIGNAL(currentRowChanged(int)),
this, SLOT(onRowChanged(int)));
connect(btn, SIGNAL(clicked(bool)),
this, SLOT(onBtnClicked(bool)));
l->addWidget(lst);
l->addWidget(btn);
setLayout(l);
}
private slots:
void onRowChanged(int);
void onBtnClicked(bool);
private:
};
inline void TestWidget::onBtnClicked(bool)
{
delete lst->takeItem(0); // triggers rowChanged
// current row number == 0 ... Correct
QString("onBtnClicked: current row number: %1") .arg(lst->currentRow()));
}
inline void TestWidget::onRowChanged(int i)
{
// new row number == 1 ... Why?
QString("onRowChanged: new row number: %1").
arg(i
));
}
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
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 :)