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. QTableWidget or QTableView
Forum Updated to NodeBB v4.3 + New Features

QTableWidget or QTableView

Scheduled Pinned Locked Moved General and Desktop
36 Posts 6 Posters 17.4k 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.
  • D Offline
    D Offline
    DaFranzl
    wrote on last edited by
    #22

    Can anybody explain how to forward declar the nested class?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #23

      [quote author="DaFranzl" date="1344438774"]Can anybody explain how to forward declar the nested class?[/quote]

      Moderators note:
      Please practise some patience. It is considdered rude to "up" your topic within a day or two, some say a week.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mlong
        wrote on last edited by
        #24

        bq. Can anybody explain how to forward declar the nested class?

        It's pretty straightforward stuff. Google can point you to a ton of good information. If you need more clarification, we'd be glad to help.

        Software Engineer
        My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DaFranzl
          wrote on last edited by
          #25

          Sorry for the up-post, but I googled a lot and visited 2 pages of links but I still dont know how to forward declare a nested class. I already tried this:

          @
          #include <QtCore>
          #include <player.h>
          #include <datasource.h>
          #include <contactmodel.h>

          class PLAYERHOLDER
          {

          public:
          static PLAYERHOLDER* getInstance();
          void createPlayer(PLAYER player);
          void updatePlayer(int id);
          void deletePlayer(int id);
          PLAYER
          findPlayer(int id);
          void loadPlayers(int teamid);

          QAbstractItemModel* model() ;
          

          private:
          PLAYERHOLDER();
          static PLAYERHOLDER thePlayerholder;
          QHash<int, PLAYER
          > playerlist;
          DATASOURCE *datasource;
          mutable CONTACTMODEL *m_model;
          };
          @

          @
          #include <playerholder.h>

          class PLAYERHOLDER;

          class CONTACTMODEL : public QAbstractTableModel
          {
          public:
          explicit CONTACTMODEL(PLAYERHOLDER* holder);

              int rowCount( const QModelIndex &parent ) const;
              int columnCount( const QModelIndex &parent ) const;
              QVariant data( const QModelIndex &index, int role ) const;
              QVariant headerData( int section, Qt::Orientation orientation, int role ) const;
              void update();
          
          
          private:
              static PLAYERHOLDER* m_playerHolder;
          };@
          

          But that didnt work :(

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #26

            How about:

            @
            #include <QtCore>
            #include <player.h>
            #include <datasource.h>
            #include <contactmodel.h>
            class QAbstractItemModel;

            class PLAYERHOLDER
            {
            private:
            class CONTACTMODEL; //forward declaration

            public:
            static PLAYERHOLDER* getInstance();
            void createPlayer(PLAYER player);
            void updatePlayer(int id);
            void deletePlayer(int id);
            PLAYER
            findPlayer(int id);
            void loadPlayers(int teamid);

            QAbstractItemModel* model() ;
            

            private:
            PLAYERHOLDER();
            static PLAYERHOLDER thePlayerholder;
            QHash<int, PLAYER
            > playerlist;
            DATASOURCE *datasource;
            mutable CONTACTMODEL *m_model;
            };
            @

            @
            //in PLAYERHOLDER.cpp

            #include <QAbstractTableModel>

            class PLAYERHOLDER::CONTACTMODEL : public QAbstractTableModel
            {
            public:
            explicit CONTACTMODEL(PLAYERHOLDER* holder)
            : QAbstractItemModel()
            { //implement here }

                int rowCount( const QModelIndex &parent ) const 
                { 
                    // implement here
                }
            
                // same for other methods
            
            private:
                PLAYERHOLDER* m_playerHolder; // NO need to make it static
            };
            

            //implement PLAYERHOLDER here under

            @

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DaFranzl
              wrote on last edited by
              #27

              Ok, so I forward declared the class, but you said i have to define the signal datachanged, the problem i have is that nested classes aren't allowed to have signal and slots. So how can i implement it? Also if I try to add Q_Object macro into CONTACTMODEL, I get compile errors about unresolved extern symbol metaObject.

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #28

                No, I did not say that. QAbstractItemModel already defines it, you just need to make sure the signal is emitted when needed. So, you don't need moc or Q_OBJECT in the class.

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DaFranzl
                  wrote on last edited by
                  #29

                  Ok, I tryed to implement the functions insertRows() and removeRows(). I have an example from my book:

                  @bool TableModel::insertRows(int row, int count, const QModelIndex&)
                  {
                  beginInsertRows(QModelIndex(), row, row + count - 1);
                  for (int i = 0; i < count; ++i)
                  zipcodes.insert(row, ZipcodeItem());
                  endInsertRows();
                  return true;
                  }@

                  But i dont think this one would work, cause it inserts items into the store. But in my case it is like, the function createPlayer() is called and then the model needs to update. Also the update function, it is called then it needs to find out where the player is stored and then edits it. But I have no idea after reading this book how to implement this with my api.

                  1 Reply Last reply
                  0
                  • I Offline
                    I Offline
                    issam
                    wrote on last edited by
                    #30

                    the best choice is QStandardItemModel (or QAbstractTableModel) + QTableView :

                    the model : to store and control data
                    the view : to display the data

                    you can also download this example : http://www.iissam.com/sources/codes.php (AHP method)

                    http://www.iissam.com/

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DaFranzl
                      wrote on last edited by
                      #31

                      Ok, i think u didnt read the conversation before;) I got a nested QAbstractTableModel class

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #32

                        [quote author="DaFranzl" date="1344544630"]Ok, I tryed to implement the functions insertRows() and removeRows(). I have an example from my book:

                        @bool TableModel::insertRows(int row, int count, const QModelIndex&)
                        {
                        beginInsertRows(QModelIndex(), row, row + count - 1);
                        for (int i = 0; i < count; ++i)
                        zipcodes.insert(row, ZipcodeItem());
                        endInsertRows();
                        return true;
                        }@

                        But i dont think this one would work, cause it inserts items into the store. But in my case it is like, the function createPlayer() is called and then the model needs to update. Also the update function, it is called then it needs to find out where the player is stored and then edits it. But I have no idea after reading this book how to implement this with my api.[/quote]

                        This code does the reverse of what you want. What you want is your store notifying your model, but the code you show is an implementation is allowing chaning your store through your model. Both are valid use cases, but they are not the same. However, the basics of what happens is the same: call beginInsertRows() directly before you add to your data store, and endInsertRows() directly after. Only, instead of doing that from the insertRows method of your CONTACTMODEL, you trigger it from your PLAYERHOLDER class' createPlayer implementation.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          DaFranzl
                          wrote on last edited by
                          #33

                          Should i call the insertRows method from createPlayer and at inserrRows() just call beginInsertRows() and endInsertRows()?

                          1 Reply Last reply
                          0
                          • A Offline
                            A Offline
                            andre
                            wrote on last edited by
                            #34

                            Did you try reading the documentation for these methods in [[doc:QAbstractItemModel]]?

                            1 Reply Last reply
                            0
                            • D Offline
                              D Offline
                              DaFranzl
                              wrote on last edited by
                              #35

                              Yeah, I already read it, I tried my solution with calling insertRows() from createPlayer() and it works.
                              @ bool insertRows(int row, int count, const QModelIndex &parent)
                              {
                              beginInsertRows(QModelIndex(),row,row + count -1);
                              endInsertRows();
                              return true;
                              }@

                              Is it also a hack like my reset() method or can I use this without worries?

                              1 Reply Last reply
                              0
                              • I Offline
                                I Offline
                                issam
                                wrote on last edited by
                                #36

                                How about : http://pepper.troll.no/s60prereleases/doc/itemviews-addressbook.html ?

                                http://www.iissam.com/

                                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