Results 1 to 2 of 2

Thread: QListView remains empty

  1. #1
    Join Date
    Feb 2014
    Qt products
    Qt4 Qt5

    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:

  2. #2
    Join Date
    Jan 2006
    Graz, Austria
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    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.


  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, 22:28
  2. QTableWidget remains at default size
    By CoderMan in forum Qt Programming
    Replies: 6
    Last Post: 7th March 2012, 19:10
  3. Dialog remains in background.
    By vjsharma_30 in forum Qt Programming
    Replies: 4
    Last Post: 15th March 2010, 22:12
  4. StatusTip remains displayed
    By emonette123 in forum Qt Programming
    Replies: 0
    Last Post: 4th April 2008, 16:32
  5. remove directory empty or not empty
    By raphaelf in forum Newbie
    Replies: 12
    Last Post: 27th October 2006, 07:30

Tags for this Thread


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.