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. MVC problem
Qt 6.11 is out! See what's new in the release blog

MVC problem

Scheduled Pinned Locked Moved General and Desktop
17 Posts 5 Posters 6.3k 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.
  • F Offline
    F Offline
    Franzk
    wrote on last edited by
    #8

    Put a newline behind your @ symbols.

    "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

    http://www.catb.org/~esr/faqs/smart-questions.html

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MarkoSiroki
      wrote on last edited by
      #9

      Hmm, I've set breakpoint and this method never gets called. Is this reason of all my problems?

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

        Might be a good indicator, yes. Do your rowCount() and columnCount() methods return sensible results?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MarkoSiroki
          wrote on last edited by
          #11

          Yes, they do, but now I've noticed I do not have reimplemented setData method. Let me try to reimplement it ... will post results ...

          1 Reply Last reply
          0
          • F Offline
            F Offline
            Franzk
            wrote on last edited by
            #12

            setData() is not really necessary if you don't allow external editing.

            What does this code portion do?
            [quote author="MarkoSiroki" date="1298526272"]
            @
            bool BSPPlayListModel::insertRows(int row,
            int count,
            const QModelIndex& parent)
            {
            //...
            for(quint64 iIndex=0; iIndex<(quint64)count; iIndex++)
            (void)new BSPPlayListItem();
            //...
            }@
            [/quote]
            More specifically, what happens with the new BSPPlayListItem?

            "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

            http://www.catb.org/~esr/faqs/smart-questions.html

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

              Franzk is right: if you only need viewing capabilities, then you don't need to reimplement any of the editing methods. That includes insertRows(), insertColumns and setData().

              Of course, you still need your own methods to tell the model that new data has arrived, but you can design that to your own liking.

              Could you tell us what data structure you use to store the data on your mp3's?

              Also: if this is your first QAbstractItemModel, you've picked the most tricky one to start with: a tree model. Those are simply not so easy to work with.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #14

                If insertRows() is called from outside the model, then setData() is also needed.

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #15

                  And yet another introduction into MVC is the "Model/View Tutorial ":http://doc.qt.nokia.com/4.7/modelview.html of the docs.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    Darryl DSouza
                    wrote on last edited by
                    #16

                    If you really do not need a tree structure, use simply QAbstractTableModel and implement data(), rowCount(), coulnCount() and headerData() functions. They are really easy for you if you have not worked with complex models.

                    Darryl D'Souza

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      MarkoSiroki
                      wrote on last edited by
                      #17

                      Well, here is code for item:
                      @
                      #ifndef BSPPLAYLISTITEM_H
                      #define BSPPLAYLISTITEM_H

                      #include <QObject>
                      #include <QtCore/QString>
                      #include <QtCore/QList>
                      #include <QtCore/QTime>

                      class BSPPlayListItem : public QObject
                      {
                      Q_OBJECT

                      public:
                      explicit BSPPlayListItem(QObject parent = 0);
                      BSPPlayListItem(const quint64 iId/
                      =0*/,
                      const QString& name/=QString()/,
                      const QString& thumbnailPath/=QString()/,
                      const QTime& length/=QTime()/,
                      BSPPlayListItem* pParent/=0/);
                      ~BSPPlayListItem();

                      inline quint64& number()
                          { return m_iNumber; }
                      inline void setNumber(const quint64& id)
                          { m_iNumber=id; }
                      inline QString& name()
                          { return m_strName; }
                      inline void setName(const QString& name)
                          { m_strName=name; }
                      inline QString& thumbnailPath()
                          { return m_strThumbnailPath; }
                      
                      inline QTime& duration()
                          { return m_tmLength; }
                      inline void setDuration(const QTime& duration)
                          { m_tmLength=duration; }
                      inline void setThumbPath(const QString& path)
                          { m_strThumbnailPath=path; }
                      
                      inline BSPPlayListItem* parent()
                          { return m_pParent; }
                      inline BSPPlayListItem* childAt(const quint64& iRow) const
                          { return m_lsChildren.value(iRow); }
                      inline quint64 rowOfChild(BSPPlayListItem* const child) const
                          { return m_lsChildren.indexOf(child); }
                      inline bool hasChildren() const
                          { return !m_lsChildren.isEmpty(); }
                      inline int childCount() const
                          { return m_lsChildren.size(); }
                      inline QList<BSPPlayListItem*>& children()
                          { return m_lsChildren; }
                      inline void insertChild(const quint64& iRow,
                                              BSPPlayListItem* const item)
                          { item->m_pParent=this; m_lsChildren.insert(iRow, item); }
                      inline void addChild(BSPPlayListItem* const item)
                          { item->m_pParent=this; m_lsChildren << item; }
                      inline void swapChildren(const quint64& iOldRow,
                                               const quint64& iNewRow)
                          { m_lsChildren.swap(iOldRow, iNewRow); }
                      BSPPlayListItem* takeChild(const quint64& iRow);
                      

                      private:
                      quint64 m_iNumber;
                      QString m_strName;
                      QString m_strThumbnailPath;
                      QTime m_tmLength;

                      BSPPlayListItem* m_pParent;
                      QList<BSPPlayListItem*> m_lsChildren;
                      

                      };

                      #endif // BSPPLAYLISTITEM_H
                      @

                      and cpp file:
                      @
                      #include "BSPPlayListItem.h"

                      BSPPlayListItem::BSPPlayListItem(QObject *parent)
                      : QObject(parent),
                      m_strName(QString()),
                      m_strThumbnailPath(QString()),
                      m_tmLength(QTime()),
                      m_pParent(0)
                      {
                      this->m_lsChildren.clear();
                      }

                      BSPPlayListItem::BSPPlayListItem(const quint64 iId,
                      const QString& name,
                      const QString& thumbnailPath,
                      const QTime& length,
                      BSPPlayListItem* pParent)
                      : m_iNumber(iId),
                      m_strName(name),
                      m_strThumbnailPath(thumbnailPath),
                      m_tmLength(length),
                      m_pParent(pParent)
                      {
                      if(m_pParent)
                      m_pParent->addChild(this);
                      }

                      BSPPlayListItem::~BSPPlayListItem()
                      {
                      qDeleteAll(m_lsChildren);
                      }

                      BSPPlayListItem* BSPPlayListItem::takeChild(const quint64& iRow)
                      {
                      BSPPlayListItem* item=this->m_lsChildren.takeAt(iRow);
                      item->m_pParent=0;

                      return item;
                      

                      }
                      @

                      The point is I must make Media Playlist like in MediaMonkey or Apple iTunes and because to sort albums alphabeticly, I thought to use QTreeView for albums and then inside each album a table of songs. This table of songs must be resizable.

                      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