Festus Hagen
15th September 2013, 05:43
Hi all,
Kinda figure someone would have already done/asked this ... I cannot find it if they have!
Learning and Tinkering with the Media Player Example (http://qt-project.org/doc/qt-5.0/qtmultimedia/multimediawidgets-player.html).
My goal is learning the underlying PlaylistModel.
Trying to add the ability to remove items from the playlist, Added:
void Player::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Delete:
if(playlistView->hasFocus())
removeFromPlaylist();
break;
default:
event->ignore();
break;
}
}
And
void Player::removeFromPlaylist()
{
QModelIndex idx = playlistView->currentIndex();
if(!idx.isValid())
return;
playlist->removeMedia(idx.row());
}
The item is removed however there are errors if within four items of the end of list.
The errors are:
QAbstractItemModel::endInsertRows: Invalid index ( 4 , 0 ) in model PlaylistModel(0x1a676848)
Of course the numbers change ....
If the last item is always the item that is removed it works fine, It appears to be trying to select the row +3 after deletion and I cannot figure out why.
Any ideas/suggestions/fixes ???
-Enjoy
fh : )_~
Kinda figure someone would have already done/asked this ... I cannot find it if they have!
Learning and Tinkering with the Media Player Example (http://qt-project.org/doc/qt-5.0/qtmultimedia/multimediawidgets-player.html).
My goal is learning the underlying PlaylistModel.
Trying to add the ability to remove items from the playlist, Added:
void Player::keyPressEvent(QKeyEvent *event)
{
switch (event->key()) {
case Qt::Key_Delete:
if(playlistView->hasFocus())
removeFromPlaylist();
break;
default:
event->ignore();
break;
}
}
And
void Player::removeFromPlaylist()
{
QModelIndex idx = playlistView->currentIndex();
if(!idx.isValid())
return;
playlist->removeMedia(idx.row());
}
The item is removed however there are errors if within four items of the end of list.
The errors are:
QAbstractItemModel::endInsertRows: Invalid index ( 4 , 0 ) in model PlaylistModel(0x1a676848)
Of course the numbers change ....
If the last item is always the item that is removed it works fine, It appears to be trying to select the row +3 after deletion and I cannot figure out why.
Any ideas/suggestions/fixes ???
-Enjoy
fh : )_~