JN
Size: a a a
JN
AS
AS
JN
C source, UTF-8 Unicode (with BOM) text
AS
C source, UTF-8 Unicode (with BOM) text
JN
M
ADD "Item 0"А получилось так:
CHANGE row: 0 addr: 0x12f0fb0 " text: Item 0
REMOVE "Item 0"
CHANGE row: -1 addr: 0x0 ""
ADD "Item 0"Т.е. удалили единственный итем, приходит сигнал что менятся выбранная строка на -1, потом следом второй сигнал и выбранная строка теперь 0 и откуда-то появляется призрачный удаленый итем.
CHANGE row: 0 addr: 0x12f0fb0 " text: Item 0"
REMOVE "Item 0"
CHANGE row: -1 addr: 0x0 "" <------- OK
CHANGE row: 0 addr: 0x12f0fb0 " text: Item 0" <------ WTF?
AS
void MainWindow::on_pushButton_clicked() {
if (ui->listWidget->currentRow() < ui->listWidget->count()) {
qDebug() << "before delete: currentRow =" << ui->listWidget->currentRow();
auto item = ui->listWidget->takeItem(ui->listWidget->currentRow());
if (item) {
qDebug() << item->data(Qt::DisplayRole) << " has been deleted";
delete item;
qDebug() << "afted delete: currentRow =" << ui->listWidget->currentRow();
}
}
}
void MainWindow::on_listWidget_currentRowChanged(int currentRow) {
qDebug() << "current row changed " << currentRow;
}
void MainWindow::on_listWidget_itemSelectionChanged() {
qDebug() << "item selection changed " << ui->listWidget->currentRow();
}
void MainWindow::on_listWidget_currentItemChanged(QListWidgetItem *current,
QListWidgetItem *previous) {
qDebug() << "current item changed: current = "
<< (current ? current->data(Qt::DisplayRole) : "null")
<< ", previous = "
<< (previous ? previous->data(Qt::DisplayRole) : "null");
}
current item changed: current = QVariant(QString, "Item3") , previous = QVariant(QString, "null")
current row changed 2
item selection changed 2
before delete: currentRow = 2
item selection changed 3 << WARNING! после удаления будет недействительным
current item changed: current = QVariant(QString, "Item4") , previous = QVariant(QString, "Item3")
current row changed 3 << WARNING! после удаления будет недействительным
QVariant(QString, "Item3") has been deleted
afted delete: currentRow = 2
M
F
F
AS
AS
M