Results 1 to 2 of 2

Thread: QListView remains empty

  1. #1
    Join Date
    Feb 2014
    Posts
    13
    Thanks
    6
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Question QListView remains empty

    Hello, I use Qt 4.8 for a project and had troubles so set up a sample project because as a newbie I have troubles finding out what's wrong.

    I use a QListView to show items information. In my real project, there will be item properties such as ID, name etc. In sample project I made a simple list of strings.

    So why is the list empty when I run the sample app?

    Thank you very much,

    Here is the code:

    https://gist.github.com/postb99/548b32546eece2e7aed6

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView remains empty

    The problem is that you derive from QStandardItemModel.

    When its index() method is called, it will always return a null index because it is empty.

    Derive from QAbstractTableModel instead, or QAbstractListModel if you want a list.

    In a full implementation your addItem() method would have to signal that rows are being added, see beginInsertRows(), endInsertRows().

    In your simple example it should still be OK, since you add both items before you set the model on the view.

    Cheers.
    _

  3. The following user says thank you to anda_skoa for this useful post:

    postb99 (17th February 2014)

Similar Threads

  1. Replies: 1
    Last Post: 29th June 2013, 23:28
  2. QTableWidget remains at default size
    By CoderMan in forum Qt Programming
    Replies: 6
    Last Post: 7th March 2012, 20:10
  3. Dialog remains in background.
    By vjsharma_30 in forum Qt Programming
    Replies: 4
    Last Post: 15th March 2010, 23:12
  4. StatusTip remains displayed
    By emonette123 in forum Qt Programming
    Replies: 0
    Last Post: 4th April 2008, 17:32
  5. remove directory empty or not empty
    By raphaelf in forum Newbie
    Replies: 12
    Last Post: 27th October 2006, 08:30

Tags for this Thread

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.