Results 1 to 7 of 7

Thread: Problem with QModelIndex

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Problem with QModelIndex

    or you can use this method
    QSqlRecord QSqlQueryModel::record ( int row ) const
    Qt Code:
    1. if (!index.isValid())
    2. return;
    3.  
    4. int id = qobject_cast<QSqlTableModel *>(index.model())->record(index.row()).value("email.id").toInt();
    To copy to clipboard, switch view to plain text mode 
    Last edited by spirit; 30th October 2008 at 09:27. Reason: updated contents

  2. #2
    Join Date
    Oct 2008
    Posts
    6
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Problem with QModelIndex

    Thanks a lot man, you are a genius
    I used this
    Qt Code:
    1. ...
    2. if (!index.isValid())
    3. return;
    4.  
    5. if (!index.column())
    6. idx = index;
    7. else
    8. idx = index.model()->index(0, index.row());//0 -- id field
    9.  
    10. int id = index.data(Qt::EditRole).toInt();
    11. ...
    To copy to clipboard, switch view to plain text mode 

    and it worked fine.

  3. #3
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 370 Times in 336 Posts

    Default Re: Problem with QModelIndex

    Quote Originally Posted by Kesy View Post
    Thanks a lot man, you are a genius
    I used this
    Qt Code:
    1. ...
    2. if (!index.isValid())
    3. return;
    4.  
    5. if (!index.column())
    6. idx = index;
    7. else
    8. idx = index.model()->index(0, index.row());//0 -- id field
    9.  
    10. int id = index.data(Qt::EditRole).toInt();
    11. ...
    To copy to clipboard, switch view to plain text mode 

    and it worked fine.
    you are wellcome. but I suggest you to use code from my last post, it is more clear to use (for this task), but in general case this one more preferred.

Similar Threads

  1. QSql*Model + QTreeView : make a tree
    By punkypogo in forum Qt Programming
    Replies: 18
    Last Post: 24th October 2008, 19:14
  2. QModelIndex problem!
    By landonmkelsey in forum Qt Programming
    Replies: 10
    Last Post: 28th August 2008, 20:46
  3. Problem with TreeView
    By init2null in forum Qt Programming
    Replies: 8
    Last Post: 25th May 2008, 10:56
  4. QAbstractItemModel newbie question
    By okellogg in forum Qt Programming
    Replies: 14
    Last Post: 18th February 2008, 13:30
  5. Replies: 6
    Last Post: 21st September 2007, 14:51

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
  •  
Qt is a trademark of The Qt Company.