Get source of next row in proxy
Hello,
I made a MusicListWidget that keeps all my songs in a QList<Song*>. I use a view and a model to show the songs in the widgets and I use a QSortFilterProxyModel to show them in alphabetic order.
If a song finishes playing (or if I press the next button), I have to play the next song in the list. But the next song in the list isn't the 'real' next song. It's the next song of the proxy.
Here's an illustration:
http://img504.imageshack.us/img504/7...anationdg2.jpg
So I made this code to find the next song but it crashes...
Code:
int MusicListWidget::getNextPosition()
{
// currentPos is the real position of the song in the list
QModelIndex sourceIndex
= model
->createIndex
(currentPos,
0);
QModelIndex proxyIndex
= proxy
->mapFromSource
(sourceIndex
);
QModelIndex newProxyIndex
= proxy
->createIndex
(proxyIndex.
row()+1,
0);
QModelIndex newModelIndex
= proxy
->mapToSource
(newProxyIndex
);
// crashed here... return newModelIndex.row();
}
Can anyone help me out?
Thanks in advance,
Gillis
Re: Get source of next row in proxy
I'm sure this code doesn't compile... createIndex() is protected and it is that way for a reason - you should never use it yourself. That's by the way why your code crashes if you made your way around it :) Try this pseudocode:
Code:
model = proxy->sourceModel();
nextProxyRow = proxy->index(currentRow+1, 0);
nextSourceRow = proxy->mapToSource(nextProxyRow);
I'm assuming "currentRow" is an integer holding the current row of the view (= the current row of the proxy model).
Re: Get source of next row in proxy
Thanks you very much! The problem was indeed that I was using createIndex (but it did compile because I made friends with the model and the proxy :)). Works like a charm with the index function :)