Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStandardItem::hasChildren returns true while removing last child

QStandardItem::hasChildren returns true while removing last child

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 500 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Landolfi
    wrote on last edited by
    #1

    When I remove a row from my QTreeView, I got a currentRowChanged signal. In the slot, I check the hasChildren property of the parent item and I get true even if it was the last children.

    QTreeView * treeView;
    treeView = new QTreeView(PageHmiSetup);
    QStandardItemModel * deviceList;
    deviceList = new QStandardItemModel(this);
    ui->treeView->setModel(deviceList);
    
    connect (ui->treeView->selectionModel(),&QItemSelectionModel::currentRowChanged,this,&PageHmiSetup::showItemInfo);
    
    

    When I remove last child and parent get focus, showItemInfo() is called and ui->treeView->currentIndex()->hasChildren() returns true. I suspect that the current row is changed before actually removing the row: should I submit a bug description to Qt? Or is there anything else I did not understand?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Landolfi said in QStandardItem::hasChildren returns true while removing last child:

      I suspect that the current row is changed before actually removing the row: should I submit a bug description to Qt?

      Where do the docs state that currentRowChanged() must be emitted before the row is removed?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3

        It's not a bug, the view updates the current index as a response to rowsAboutToBeRemoved so it's before the actual rows get removed so the behaviour you experience is totally normal and intended.

        To react after the rows have actually been removed add Qt::QueuedConnection as an extra argument to your connect()

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        4

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved