Results 1 to 2 of 2

Thread: Media Player Example - removeMedia

  1. #1
    Join Date
    Jul 2013
    Posts
    15
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Media Player Example - removeMedia

    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.
    My goal is learning the underlying PlaylistModel.

    Trying to add the ability to remove items from the playlist, Added:
    Qt Code:
    1. void Player::keyPressEvent(QKeyEvent *event)
    2. {
    3. switch (event->key()) {
    4. case Qt::Key_Delete:
    5. if(playlistView->hasFocus())
    6. removeFromPlaylist();
    7. break;
    8. default:
    9. event->ignore();
    10. break;
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    And
    Qt Code:
    1. void Player::removeFromPlaylist()
    2. {
    3. QModelIndex idx = playlistView->currentIndex();
    4. if(!idx.isValid())
    5. return;
    6. playlist->removeMedia(idx.row());
    7. }
    To copy to clipboard, switch view to plain text mode 

    The item is removed however there are errors if within four items of the end of list.
    The errors are:
    Qt Code:
    1. QAbstractItemModel::endInsertRows: Invalid index ( 4 , 0 ) in model PlaylistModel(0x1a676848)
    To copy to clipboard, switch view to plain text mode 
    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 : )_~
    Last edited by Festus Hagen; 15th September 2013 at 06:05.

  2. #2
    Join Date
    Jun 2014
    Posts
    1
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Media Player Example - removeMedia

    Hi Festus,
    I know, it's a little bit late, but recently I had this problem, too. Here is the solution:

    In playlistmodel.cpp you has to change the endRemoveItems method. This method should call endRemoveRows, not endInsertRows.
    Then you can overwrite removeRow with public access modifier:

    Qt Code:
    1. //in header file the default value of parent parameter is a new instance of QModelIndex()
    2.  
    3. bool PlaylistModel::removeRow(int row, const QModelIndex &parent){
    4.  
    5. if(0 > row || (row + 1) > rowCount(parent))
    6. return false;
    7.  
    8. beginRemoveRows(parent, row, row);
    9.  
    10. foreach(QModelIndex index, _data.keys())
    11. if(row == index.row()){
    12. _data.remove(index);
    13. break;
    14. }
    15.  
    16. endRemoveRows();
    17.  
    18. return true;
    19. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by fant; 1st June 2014 at 16:00.

Similar Threads

  1. my media player
    By Fafa in forum Qt Programming
    Replies: 0
    Last Post: 23rd July 2011, 06:50
  2. How to make Media Player
    By v-6 in forum Newbie
    Replies: 3
    Last Post: 8th November 2010, 10:02
  3. media player problem
    By emrez in forum Qt Programming
    Replies: 1
    Last Post: 16th July 2010, 17:50
  4. Media Player for Windows.
    By merry in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2008, 06:49
  5. media player in qtopia
    By sar_van81 in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 19th December 2007, 11:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.