[Qt-qml] emit data on a QAbstracListModel does not update the QML ListView.
Bartosh Wroblevksy
bartosh at live.com
Tue Sep 14 18:36:51 CEST 2010
Hello Steve,
Thank you for filing the BR. I have a few questions.
1) What's the number of the bug?
2) I have trouble seeing how in this case, moving rows and changing data is not equivalent. In fact,unless my morning coffee was not caffeinated.
If I write
m_elements[1] ="x"; emit dataChanged(index(1,0), index(1,0));
Should I not expect to see the QML listview change?
3) beginResetModel() and endResetModel() is clearly not what I want. My application flickers horribly. In fact I hadinitially tried an emit modelReset() which also made my application flick horribly. I was hoping to avoid the flickerwith an emit dataChanged. Until this bug gets fixed, is there any better alternative?
4) You mention >*plus* updating persistent indexes in between.>Sorry, can you elaborate on this?
5) You wrote
> + beginMoveRows(QModelIndex(), 0, 0, QModelIndex(), 2);> m_elements.move(0,1);> + endMoveRows();
Since the destination child is 1, I would have expected to write
> + beginMoveRows(QModelIndex(), 0, 0, QModelIndex(), 1);> m_elements.move(0,1);> + endMoveRows();
but then again, my coffee may be decaffeinated.
Thanks for your help,Christopher
> From: steveire at gmail.com
> To: qt-qml at trolltech.com
> Date: Tue, 14 Sep 2010 15:58:54 +0200
> Subject: Re: [Qt-qml] emit data on a QAbstracListModel does not update the QML ListView.
>
> Bartosh Wroblevksy wrote:
>
> >
> > Hi,
> >
> > I have an example in attachment and don't see what I am doing wrong.
> > Essentially, in this example at least, I emit dataChanged in a model in a
> > cpp file and the QML ListView hooked up to it refuses to update. the qml
> > file is LibraryList.qmlthe model is in model.cpp What am I doing wrong?
> > Thanks, Bartosh
>
> If you move things, you need to communcate that you are moving things, not
> that you are changing data. You do that by either using
> beginMoveRows/endMoveRows or with layoutAboutToBeChanged/layoutChanged
> *plus* updating persistent indexes in between.
>
> $ git diff
> diff --git a/model.cpp b/model.cpp
> index 3c20b7f..f6750eb 100644
> --- a/model.cpp
> +++ b/model.cpp
> @@ -52,11 +52,13 @@ QVariant Model::data(const QModelIndex &index, int role
> ) const
>
> void Model::move()
> {
> + beginMoveRows(QModelIndex(), 0, 0, QModelIndex(), 2);
> m_elements.move(0,1);
> + endMoveRows();
>
> qDebug() << m_elements;
>
> - emit dataChanged(index(0,0), index(1,0));
> +// emit dataChanged(index(0,0), index(1,0));
>
> }
>
> Unfortunately there is a bug in the qml handling of moves. so the above
> doesn't work correctly. I'll file a BR.
>
> What will work though is using beginResetModel and endResetModel.
>
> All the best,
>
> Steve.
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-qml
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100914/22b12f7e/attachment.html
More information about the Qt-qml
mailing list