Menu instantiator's starange bechaviour when remove tems from model



  • This is crosspost from "stackoverflow":http://stackoverflow.com/questions/19124156/qtquick-menu-instantiator-notify-about-changed-rows.

    I have menu items model and Instantiator for it.

    @Menu {
    id: backContextMenu
    Instantiator {
    model: backModel
    MenuItem {
    text: model.text
    }
    onObjectAdded: {
    console.log("QML: object added: " + object.text + ", index= " + index);
    backContextMenu.insertItem(index,object)
    }
    onObjectRemoved: {
    backContextMenu.removeItem(object)
    console.log("QML: object removed: " + object.text);
    }
    }
    }@

    When I add any item to model at index 0 signal objectAdded is emitted with new MenuItem and index=0 as expected. But if I want to drop some items from model (for example, I have ["a";"b";"c";"d"] in model and want to remove "a" and "b") menu items are dropped from another side ("c" and "d" are dropped, "a" and "b" are still alive). After some hacking I found workaround: If I remove n items from the beginning of model I should write

    @beginRemoveRows(QModelIndex(), _items.count()-n, _items.count()-1);@

    instead of

    @beginRemoveRows(QModelIndex(), 0, n-1);@

    Any ideas why items are removed from another side? I have "demo":https://github.com/Kakadu/qtquick_test_instantiator for you.



  • I have created patch for this "bug":https://bugreports.qt-project.org/browse/QTBUG-33847


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.