1

Topic: Incorrect index in QListWidget at line delete

Actually, the problem is described here: http://www.qtforum.org/article/33720/pr … ignal.html I.e. at removal not the last line with the help, say, listWidget-> takeItem (int) the signal itemSelectionChanged () (and currentRowChanged (int)) is generated and the current selected line skips for the line below that which was deleted. What it generally for delirium? How it can be gone round? In , for example, such idiocy is not present. On Qt 5.9.2 all as also the same, as 7 years ago. QTableWidget behaves similarly. I can something I do not understand and it is the artful plan TM?

2

Re: Incorrect index in QListWidget at line delete

Hello, XOOIOOX, you wrote: XOO> Actually, the problem is described here: http://www.qtforum.org/article/33720/pr … ignal.html XOO> I.e. at removal not the last line with the help, say, listWidget-> takeItem (int) the signal itemSelectionChanged () (and currentRowChanged (int)) is generated and the current selected line skips for the line below that which was deleted. What it generally for delirium? How it can be gone round? In , for example, such idiocy is not present. XOO> On Qt 5.9.2 all as also the same, as 7 years ago. QTableWidget behaves similarly. I can something I do not understand and it is the artful plan TM? Qt 5.9.3: In ListWidget four elements Item1, Item2, Item3, Item4: 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");} I delete Item3: 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 current item changed: current = QVariant (QString, "Item4"), previous = QVariant (QString, "Item3") current row changed 3 QVariant (QString, "Item3") has been deleted afted delete: currentRow = 2 it is amusing, while physically Item it is not remote, currentRowChanged and itemSelectionChanged are caused with incorrect parameter 3 though after physical removal item-a, currentRow recovers true value, but without the notification. And here currentItemChanged behaves as it is necessary, rely on it.

3

Re: Incorrect index in QListWidget at line delete

Hello, Anatoly Shirokov, you wrote: > though after physical removal item-a, currentRow recovers true value, but without the notification. Really. The Zanjatno-neprjatnyj fact. While got out that once again I cause listWidget-> currentRow () after removal  in a removal method. > And here currentItemChanged behaves as it is necessary, rely on it. I will try to alter with it. Thanks!

4

Re: Incorrect index in QListWidget at line delete

Hello, Anatoly Shirokov, you wrote: > And here currentItemChanged behaves as it is necessary, rely on it. Checked up. Actually, no. It too produces an incorrect index and as it is caused during line delete. For example, such implementation://~~~ connect (listWidget, SIGNAL (currentItemChanged (QListWidgetItem *, QListWidgetItem *)), this, SLOT (listCurrentItemChanged (QListWidgetItem *, QListWidgetItem *)));//~~~ void TEST0095:: listCurrentItemChanged (QListWidgetItem *current, QListWidgetItem *previous) {if (current) {currentListIndex = listWidget-> row (current);//all the same here not that index std:: cout <<"currentListItem changed:" <<currentListIndex <<std:: endl;}} There is a unique variant of an additional call listWidget-> currentRow () after removal .