Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QStringListModel items not showing in QListView

QStringListModel items not showing in QListView

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 2.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Q Offline
    Q Offline
    Qt_User72653
    wrote on last edited by
    #1

    I have a QStringListModel as the model for a QListView, but the strings aren't showing in the list view. If I switch it to a QTableView or QComboBox it shows the strings, but I can't get it to work with a list view.

    I have the model here. The QListView's model is set in the MainWindow's constructor.

    I've been stuck on this for a few days now, and I can't seem to find anything that would point me in the right direction, so any help is appreciated.

    JonBJ 1 Reply Last reply
    0
    • Q Qt_User72653

      I have a QStringListModel as the model for a QListView, but the strings aren't showing in the list view. If I switch it to a QTableView or QComboBox it shows the strings, but I can't get it to work with a list view.

      I have the model here. The QListView's model is set in the MainWindow's constructor.

      I've been stuck on this for a few days now, and I can't seem to find anything that would point me in the right direction, so any help is appreciated.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @Qt_User72653
      Is http://www.bogotobogo.com/Qt/Qt5_QListView_QStringListModel_ModelView_MVC.php helpful?
      Or briefer (it's Qt4) https://stackoverflow.com/questions/5802313/qt4-qstringlistmodel-in-qlistview ?

      Q 1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi and welcome to devnet,

        In addition to @JNBarchan, why are you using QStringListModel since you manage everything by hand anyway ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Q 1 Reply Last reply
        0
        • JonBJ JonB

          @Qt_User72653
          Is http://www.bogotobogo.com/Qt/Qt5_QListView_QStringListModel_ModelView_MVC.php helpful?
          Or briefer (it's Qt4) https://stackoverflow.com/questions/5802313/qt4-qstringlistmodel-in-qlistview ?

          Q Offline
          Q Offline
          Qt_User72653
          wrote on last edited by
          #4

          @JNBarchan Thanks, I'll take a look at these.

          1 Reply Last reply
          0
          • SGaistS SGaist

            Hi and welcome to devnet,

            In addition to @JNBarchan, why are you using QStringListModel since you manage everything by hand anyway ?

            Q Offline
            Q Offline
            Qt_User72653
            wrote on last edited by
            #5

            @SGaist

            I'm not sure what you mean? Should I use an item-based ListView instead?

            I'm still new to Qt and this is a portfolio project so I'm trying to do this 'by the book', using best practices.

            1 Reply Last reply
            0
            • Q Offline
              Q Offline
              Qt_User72653
              wrote on last edited by
              #6

              So I put a call to setStringList() in the constructor of EntryModel and removed the overwritten rowCount() and data() functions, and it's working. I was using a class that was inheriting from QAbstractListModel as reference for EntryModel, which is why I originally overwrote rowCount() and data(), though, I didn't need to.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved