Results 1 to 3 of 3

Thread: beginInsertRows was not declared ???

  1. #1
    Join Date
    Feb 2007
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default beginInsertRows was not declared ???

    Hi all.

    • My class, 'H5Model', is a QAbstractItemModel subclass.
    • It is resized, on demand, when the QTreeView item is clicked.
    • The class built fine until I added 'insertRows(...)' functionality using 'beginInsertRows(...)' and 'endInsertRows()' in the implementation, I get 2 build errors saying:
      Qt Code:
      1. 'beginInsertRows' was not declared in this scope.
      To copy to clipboard, switch view to plain text mode 
      and
      Qt Code:
      1. 'endInsertRows' was not declared in this scope.
      To copy to clipboard, switch view to plain text mode 
    • The declaration and implementation are below.
    • 'H5Node::loadChildren()' is called twice, first time returns the number of children, second time actually appends the children to the data structure. (H5Node is the item data structure)
    • I'm using Qt-4.5 last updated from the git repository on June 3, 2009.
    • I'm using Qt-Creator and gcc when building.
    • The build directory has been cleaned completely and qmake re-run before attempting to build.
    • The "editabletreemodel" Qt example, which is similar, builds without any trouble.

    So, given the situtation as it is stated above, I am baffled.
    I certainly appreciate your help.

    ~travlr

    h5model.h
    Qt Code:
    1. #ifndef H5MODEL_H
    2. #define H5MODEL_H
    3. #include <QAbstractItemModel>
    4. #include <QModelIndex>
    5. #include <QVariant>
    6.  
    7. class H5Node;
    8.  
    9. class H5Model : public QAbstractItemModel
    10. {
    11. Q_OBJECT
    12.  
    13. public:
    14. H5Model(QObject* parent=0);
    15. ~H5Model();
    16.  
    17.  
    18. // readonly
    19. QVariant data(const QModelIndex & index, int role) const;
    20. Qt::ItemFlags flags(const QModelIndex & index) const;
    21. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
    22. QModelIndex index(int row, int column, const QModelIndex & parent) const;
    23. QModelIndex parent(const QModelIndex & index) const;
    24. int rowCount(const QModelIndex & parent=QModelIndex()) const;
    25. int columnCount(const QModelIndex & parent=QModelIndex()) const;
    26.  
    27. // resizeable
    28. bool insertRows(int row, int count, const QModelIndex & parent=QModelIndex());
    29.  
    30. public slots:
    31. void h5TreeClicked(const QModelIndex & index);
    32.  
    33. private:
    34. // variables
    35. H5Node* m_rootNode;
    36. };
    37.  
    38. #endif // H5MODEL_H
    To copy to clipboard, switch view to plain text mode 
    h5model.cpp
    Qt Code:
    1. #include <QtGui>
    2. #include <QDebug>
    3. #include "h5node.h"
    4. #include "h5model.h"
    5.  
    6.  
    7. H5Model::H5Model(QObject* parent) : QAbstractItemModel(parent)
    8. {
    9. m_rootNode = new H5Node(H5Node::Root, "/data/data", 0);
    10. m_rootNode->loadChildren();
    11. }
    12.  
    13.  
    14. H5Model::~H5Model()
    15. {
    16. delete m_rootNode;
    17. }
    18.  
    19.  
    20. int H5Model::columnCount(const QModelIndex & parent) const
    21. {
    22. if (parent.isValid())
    23. return static_cast<H5Node*>(parent.internalPointer())->columnCount();
    24. else
    25. return m_rootNode->columnCount();
    26. }
    27.  
    28.  
    29. QVariant H5Model::data(const QModelIndex & index, int role) const
    30. {
    31. if (!index.isValid() || role != Qt::DisplayRole)
    32. return QVariant();
    33. H5Node* node = static_cast<H5Node*>(index.internalPointer());
    34. return node->data(index.column());
    35. }
    36.  
    37.  
    38. Qt::ItemFlags H5Model::flags(const QModelIndex & index) const
    39. {
    40. if (!index.isValid())
    41. return 0;
    42. return Qt::ItemIsEditable | Qt::ItemIsEnabled | Qt::ItemIsSelectable;
    43. }
    44.  
    45.  
    46. QVariant H5Model::headerData(int section, Qt::Orientation orientation, int role) const
    47. {
    48. if (orientation == Qt::Horizontal && role == Qt::DisplayRole) {
    49. if (section == 0)
    50. return "Name";
    51. else if (section == 1)
    52. return "Type";
    53. else
    54. return QVariant();
    55. }
    56. return QVariant();
    57. }
    58.  
    59.  
    60. QModelIndex H5Model::index(int row, int column, const QModelIndex & parent) const
    61. {
    62. if (!hasIndex(row, column, parent))
    63. return QModelIndex();
    64. H5Node* parentItem;
    65. if (!parent.isValid())
    66. parentItem = m_rootNode;
    67. else
    68. parentItem = static_cast<H5Node*>(parent.internalPointer());
    69. H5Node* childItem = parentItem->child(row);
    70. if (childItem)
    71. return createIndex(row, column, childItem);
    72. else
    73. return QModelIndex();
    74. }
    75.  
    76.  
    77. QModelIndex H5Model::parent(const QModelIndex & index) const
    78. {
    79. if (!index.isValid())
    80. return QModelIndex();
    81. H5Node* childItem = static_cast<H5Node*>(index.internalPointer());
    82. H5Node* parentItem = childItem->parent();
    83. if (parentItem == m_rootNode)
    84. return QModelIndex();
    85. return createIndex(parentItem->row(), 0, parentItem);
    86. }
    87.  
    88.  
    89. int H5Model::rowCount(const QModelIndex & parent) const
    90. {
    91. H5Node* parentItem;
    92. if (parent.column() > 0)
    93. return 0;
    94. if (!parent.isValid())
    95. parentItem = m_rootNode;
    96. else
    97. parentItem = static_cast<H5Node*>(parent.internalPointer());
    98. return parentItem->childCount();
    99. }
    100.  
    101.  
    102. bool insertRows(int row, int count, const QModelIndex & parent)
    103. {
    104. Q_UNUSED(row)
    105. Q_UNUSED(count)
    106. H5Node* node = static_cast<H5Node*>(parent.internalPointer());
    107. int numChildren = node->loadChildren();
    108. if (numChildren == 0) {
    109. return false;
    110. }
    111. beginInsertRows(parent, 0, numChildren - 1);
    112. node->loadChildren();
    113. endInsertRows();
    114. return true;
    115. }
    116.  
    117.  
    118. // slot
    119. void H5Model::h5TreeClicked(const QModelIndex & index)
    120. {
    121. insertRows(0, 0, index);
    122. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by travlr; 6th June 2009 at 20:08.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: beginInsertRows was not declared ???

    Your "insertRows" function is not part of your class. You made it a standalone function instead of a class method.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    travlr (6th June 2009)

  4. #3
    Join Date
    Feb 2007
    Posts
    24
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: beginInsertRows was not declared ???

    Wysota I swear I looked for a solution a hundred times before I posted.

    Doh!!!

    I can't believe I did not see it...

    ... I HATE stupid mistakes.

    Thank you so much... again!

    ~travlr
    Last edited by travlr; 6th June 2009 at 21:28.

Similar Threads

  1. qssl
    By jsmith in forum Qt Programming
    Replies: 29
    Last Post: 7th April 2009, 22:21
  2. Installation on Fedora Core 4
    By jcr in forum Installation and Deployment
    Replies: 3
    Last Post: 29th January 2009, 01:34
  3. nmake error during .pro compiling
    By mattia in forum Installation and Deployment
    Replies: 5
    Last Post: 18th June 2008, 10:15
  4. Just for fun game
    By vermarajeev in forum Qt-based Software
    Replies: 6
    Last Post: 13th December 2007, 21:52
  5. Error compiling psql plugin
    By vieraci in forum Installation and Deployment
    Replies: 4
    Last Post: 7th October 2007, 02:49

Bookmarks

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.