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:
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();
}
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();
}
To copy to clipboard, switch view to plain text mode
Can anyone help me out?
Thanks in advance,
Gillis
Bookmarks