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. Data not displaying on the QTreeView, QTableView,QListView classes
Forum Updated to NodeBB v4.3 + New Features

Data not displaying on the QTreeView, QTableView,QListView classes

Scheduled Pinned Locked Moved Unsolved General and Desktop
21 Posts 3 Posters 4.0k Views
  • 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.
  • JonBJ JonB

    @thippu
    As @VRonin asked, how do we know from the code you post what the scope/lifetime of your AddressbookModel instance is?

    T Offline
    T Offline
    thippu
    wrote on last edited by thippu
    #11

    @JonB I did convert all the objects from stack memory to heap, I'm not getting what you need?

    1 Reply Last reply
    0
    • JonBJ JonB

      @thippu
      As @VRonin asked, how do we know from the code you post what the scope/lifetime of your AddressbookModel instance is?

      T Offline
      T Offline
      thippu
      wrote on last edited by
      #12

      @JonB
      And also I did modelTest, There was no error.

      1 Reply Last reply
      0
      • JonBJ JonB

        @thippu
        As @VRonin asked, how do we know from the code you post what the scope/lifetime of your AddressbookModel instance is?

        T Offline
        T Offline
        thippu
        wrote on last edited by thippu
        #13

        @JonB changed all to the heap, I think they will stay till application die, right?
        code I have changed:

        Widget::Widget(QWidget *parent)
        : QWidget(parent)
        {
        QFile file("path");
        if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
        {
        qDebug()<<"can't access the file";
        }
        QString *addresses=new QString(QString::fromUtf8(file.readAll()));
        Addressbookmodel *model=new Addressbookmodel(addresses,this);
        
        QListView *listView=new QListView();
        listView->setModel(model);
        listView->setModelColumn(0);
        listView->show();
        
        QTreeView *treeView=new QTreeView;
        treeView.setModel(model);
        treeView.show();
        
        QTableView *tableView=new QTableView;
        tableView.setModel(model);
        tableView.show();
        
        setMiniumSize(800,400);
        QVBoxLayout *Vlayout=new QVBoxLayout(this);
        Vlayout->addWidget(listView);
        Vlayout->addWidget(treeView);
        Vlayout->addWidget(tableView);
        }
        
        JonBJ 1 Reply Last reply
        0
        • T thippu

          @JonB changed all to the heap, I think they will stay till application die, right?
          code I have changed:

          Widget::Widget(QWidget *parent)
          : QWidget(parent)
          {
          QFile file("path");
          if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
          {
          qDebug()<<"can't access the file";
          }
          QString *addresses=new QString(QString::fromUtf8(file.readAll()));
          Addressbookmodel *model=new Addressbookmodel(addresses,this);
          
          QListView *listView=new QListView();
          listView->setModel(model);
          listView->setModelColumn(0);
          listView->show();
          
          QTreeView *treeView=new QTreeView;
          treeView.setModel(model);
          treeView.show();
          
          QTableView *tableView=new QTableView;
          tableView.setModel(model);
          tableView.show();
          
          setMiniumSize(800,400);
          QVBoxLayout *Vlayout=new QVBoxLayout(this);
          Vlayout->addWidget(listView);
          Vlayout->addWidget(treeView);
          Vlayout->addWidget(tableView);
          }
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #14

          @thippu

          Addressbookmodel *model=new Addressbookmodel(addresses,this);
          treeView.setModel(&model);
          tableView.setModel(&model);
          

          Now that model is a pointer, why the &s?

          T 2 Replies Last reply
          2
          • JonBJ JonB

            @thippu

            Addressbookmodel *model=new Addressbookmodel(addresses,this);
            treeView.setModel(&model);
            tableView.setModel(&model);
            

            Now that model is a pointer, why the &s?

            T Offline
            T Offline
            thippu
            wrote on last edited by
            #15

            @JonB Sorry, typo mistake.

            1 Reply Last reply
            0
            • JonBJ JonB

              @thippu

              Addressbookmodel *model=new Addressbookmodel(addresses,this);
              treeView.setModel(&model);
              tableView.setModel(&model);
              

              Now that model is a pointer, why the &s?

              T Offline
              T Offline
              thippu
              wrote on last edited by
              #16

              @JonB I did copy and paste from the early reply, So

              1 Reply Last reply
              0
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #17

                I'm surprised you don't get into stack overflow.
                AddressbookModel::rowCount and AddressbookModel::columnCount form an infinitely deep tree.

                You should return 0; if the parent argument isValid()

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                T 2 Replies Last reply
                1
                • VRoninV VRonin

                  I'm surprised you don't get into stack overflow.
                  AddressbookModel::rowCount and AddressbookModel::columnCount form an infinitely deep tree.

                  You should return 0; if the parent argument isValid()

                  T Offline
                  T Offline
                  thippu
                  wrote on last edited by
                  #18

                  @VRonin okay,
                  In the Addressbookmodel.cpp
                  I changed the code to :

                  int Addressbookmodel::rowCount(const QModelIndex &parent) const
                  {
                     if(parent.isValid())
                  {
                    return 0;
                  }
                  return addressbook.count-2;
                  }
                  
                  
                  int Addressbookmodel::columnCount(const QModelIndex &parent)
                  const
                  {
                    if(parent.isValid())
                    {
                     return 0;
                    }
                  return addressbook.at(0).count();
                  }
                  
                  

                  I don't know why it is not used in the book and why am not getting data on the widgets still?.

                  1 Reply Last reply
                  0
                  • VRoninV VRonin

                    I'm surprised you don't get into stack overflow.
                    AddressbookModel::rowCount and AddressbookModel::columnCount form an infinitely deep tree.

                    You should return 0; if the parent argument isValid()

                    T Offline
                    T Offline
                    thippu
                    wrote on last edited by
                    #19

                    @VRonin Can share me an example that helps me to understand how to create QTreeView model and subclass it?, so from this I can able to create my own models successfully.

                    VRoninV 1 Reply Last reply
                    0
                    • T thippu

                      @VRonin Can share me an example that helps me to understand how to create QTreeView model and subclass it?, so from this I can able to create my own models successfully.

                      VRoninV Offline
                      VRoninV Offline
                      VRonin
                      wrote on last edited by
                      #20

                      @thippu said in Data not displaying on the QTreeView, QTableView,QListView classes:

                      Can share me an example that helps me to understand how to create QTreeView model and subclass it?

                      http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html

                      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                      ~Napoleon Bonaparte

                      On a crusade to banish setIndexWidget() from the holy land of Qt

                      T 1 Reply Last reply
                      1
                      • VRoninV VRonin

                        @thippu said in Data not displaying on the QTreeView, QTableView,QListView classes:

                        Can share me an example that helps me to understand how to create QTreeView model and subclass it?

                        http://doc.qt.io/qt-5/qtwidgets-itemviews-simpletreemodel-example.html

                        T Offline
                        T Offline
                        thippu
                        wrote on last edited by
                        #21

                        @VRonin , Thank you.

                        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