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. QStandardItemModel sibling always returns valid index [Qt 5.0]

QStandardItemModel sibling always returns valid index [Qt 5.0]

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.6k 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.
  • P Offline
    P Offline
    prauat
    wrote on last edited by
    #1

    @
    #include <QCoreApplication>
    #include <QStandardItemModel>
    #include <qDebug>

    int main(int argc, char *argv[])
    {
    QCoreApplication a(argc, argv);
    QStandardItemModel *model = new QStandardItemModel();

    model->appendRow(new QStandardItem("1"));
    model->appendRow(new QStandardItem("2"));

    QModelIndex idx = model->index(0,0);
    qDebug() << ((idx.isValid()) ? idx.data(Qt::DisplayRole) : "Invalid index");

    idx = idx.sibling(1,0);
    qDebug() << ((idx.isValid()) ? idx.data(Qt::DisplayRole) : "Invalid index");

    idx = idx.sibling(666,0); //evil -- this is out of range
    qDebug() << ((idx.isValid()) ? idx.data(Qt::DisplayRole) : "Invalid index");

    return a.exec();
    }
    @
    Output:
    QVariant(QString, "1")
    QVariant(QString, "2")
    QVariant(Invalid)

    Should I consider this as a bug?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      prady_80
      wrote on last edited by
      #2

      This is not a BUG.
      If you see QAbstractItemModel::data which is called by QStandardItemModel::data...
      The doc clearly states that, an invalid QVariant is returned instead of returning 0.
      Therefore the o/p of your program is:
      QVariant(QString, "1")
      QVariant(QString, "2")
      QVariant(Invalid)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        prauat
        wrote on last edited by
        #3

        QModelIndex QAbstractItemModel::sibling(int row, int column, const QModelIndex & index) const [virtual]

        Returns the sibling at row and column for the item at index, or an invalid QModelIndex if there is no sibling at that location.

        so the case is not about the QVariant which is invalid from obvious reasons but why the index returned by sibling is valid

        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