Results 1 to 2 of 2

Thread: invalid QModelIndex

  1. #1
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default invalid QModelIndex

    Hello.
    I try to write QAbstractTableModel but i have problem with index.
    My test class:
    Qt Code:
    1. class cmodel : public QAbstractTableModel
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. cmodel( QObject *parent = 0);
    7. ~cmodel();
    8.  
    9. QVariant data(const QModelIndex &index, int role) const;
    10. bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::DisplayRole);
    11. int rowCount(const QModelIndex &parent) const;
    12. int columnCount(const QModelIndex &parent) const;
    13. QVariant headerData(int section, Qt::Orientation orientation, int role) const;
    14. Qt::ItemFlags flags(const QModelIndex &index) const;
    15.  
    16. private:
    17. QStringList listaStr, listaUrl;
    18. };
    To copy to clipboard, switch view to plain text mode 
    and function
    Qt Code:
    1. void MainWindow::on_pushButton_clicked()
    2. {
    3. str << "1" << "2" << "3";
    4. cmodel *m = new cmodel( this );
    5. QModelIndex index = m->index( 0, 0, QModelIndex() );
    6. m->setData( index, str, Qt::DisplayRole );
    7. ui->tableView->setModel( m );
    8. }
    To copy to clipboard, switch view to plain text mode 

    but in setData my index is invalid ( index.isValid() is false ).
    Why is that?

    Thanks for any suggestion and sorry for my "enrgish"
    best regards

  2. #2
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: invalid QModelIndex

    My fault,
    I forget to "add" insertRows. Right now everything works as expected.

    Best regards

Similar Threads

  1. getting data & QModelIndex
    By alexandernst in forum Newbie
    Replies: 3
    Last Post: 6th August 2009, 19:43
  2. QModelIndex::parent question
    By QPlace in forum Qt Programming
    Replies: 4
    Last Post: 26th June 2009, 12:26
  3. Problem with QModelIndex
    By Kesy in forum Qt Programming
    Replies: 6
    Last Post: 30th October 2008, 08:44
  4. QModelIndex problem!
    By landonmkelsey in forum Qt Programming
    Replies: 10
    Last Post: 28th August 2008, 19:46
  5. Replies: 3
    Last Post: 7th May 2006, 17:07

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.