Results 1 to 3 of 3

Thread: Get source of next row in proxy

  1. #1
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default 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:


    So I made this code to find the next song but it crashes...
    Qt Code:
    1. int MusicListWidget::getNextPosition()
    2. {
    3. // currentPos is the real position of the song in the list
    4. QModelIndex sourceIndex = model->createIndex(currentPos, 0);
    5. QModelIndex proxyIndex = proxy->mapFromSource(sourceIndex);
    6. QModelIndex newProxyIndex = proxy->createIndex(proxyIndex.row()+1, 0);
    7. QModelIndex newModelIndex = proxy->mapToSource(newProxyIndex); // crashed here...
    8. return newModelIndex.row();
    9. }
    To copy to clipboard, switch view to plain text mode 
    Can anyone help me out?

    Thanks in advance,
    Gillis

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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:
    Qt Code:
    1. model = proxy->sourceModel();
    2. nextProxyRow = proxy->index(currentRow+1, 0);
    3. nextSourceRow = proxy->mapToSource(nextProxyRow);
    To copy to clipboard, switch view to plain text mode 

    I'm assuming "currentRow" is an integer holding the current row of the view (= the current row of the proxy model).

  3. #3
    Join Date
    Aug 2008
    Posts
    35
    Thanks
    7
    Thanked 3 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default 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

Similar Threads

  1. QT4.4.3 embedded qvfb
    By damien in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 14th November 2008, 18:50
  2. QT Network Proxy Configuration
    By suresh in forum Qt Programming
    Replies: 7
    Last Post: 28th September 2007, 01:16
  3. QTcpSocket - Proxy problem
    By vishesh in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2007, 23:48
  4. out of source qtopiamake???
    By izico in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 20th March 2007, 18:31
  5. Replies: 11
    Last Post: 24th March 2006, 06:40

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.