Results 1 to 4 of 4

Thread: getting entry from QListView

  1. #1
    Join Date
    Mar 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default getting entry from QListView

    Hi,

    i have a QListView with an underlying QStringList as model, now i want to read out the currently selected string in my listView for further use. How would i do that?

  2. #2
    Join Date
    Feb 2010
    Location
    Finland
    Posts
    7
    Thanks
    1
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: getting entry from QListView

    Here's an example how I would do it:
    Qt Code:
    1. QListView list;
    2. QString data;
    3. .
    4. .
    5. .
    6. data=list.data(list.currentIndex(),0).toString();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: getting entry from QListView

    Use QAbstractItemView::currentIndex() and QModelIndex::data():
    Qt Code:
    1. QString string = PointerToYourListView->currentIndex().data().toString();
    To copy to clipboard, switch view to plain text mode 
    You might want check if current index is valid.

  4. The following user says thank you to Lykurg for this useful post:

    geleven (6th April 2010)

  5. #4
    Join Date
    Mar 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: getting entry from QListView

    thanks, works perfectly!

Similar Threads

  1. Procedure entry point not found
    By Ishmael in forum Installation and Deployment
    Replies: 1
    Last Post: 9th October 2009, 18:57
  2. Multiline entry in a QMenu
    By tyrdal in forum Qt Programming
    Replies: 0
    Last Post: 28th September 2009, 12:54
  3. Procedure entry point not located
    By Hannibal in forum Qt Programming
    Replies: 2
    Last Post: 8th October 2008, 17:13
  4. Windws Taskbar Entry
    By December in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2007, 12:53
  5. Add a entry to the application menu
    By mace in forum Qt Programming
    Replies: 1
    Last Post: 28th April 2006, 07:32

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.