supergillis
16th November 2008, 14:46
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/786/explanationdg2.jpg
So I made this code to find the next song but it crashes...
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
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/786/explanationdg2.jpg
So I made this code to find the next song but it crashes...
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