Results 1 to 4 of 4

Thread: Can a QSqlModel be converted to a QStandardItemModel

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Can a QSqlModel be converted to a QStandardItemModel

    Is there a more straightforward way to convert a QSqlModel to a QStandardItemModelOther than:
    Qt Code:
    1. qstandarditemmodel->insertRows(0, qsqlmodel->rowCount());
    2. qstandarditemmodel->insertColumns(0, qsqlmodel->columnCount());
    3. for(int c=0; c<qsqlmodel->columnCount(); c++)
    4. {
    5. qstandarditemmodel->setHeaderData(c, Qt::Horizontal, qsqlmodel->headerData(c, Qt::Horizontal));
    6. for(int r=0; r<qsqlmodel->rowCount(); r++)
    7. {
    8. qstandarditemmodel->setData(qstandarditemmodel->index(r, c), qsqlmodel->record(r).value(c));
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance
    Last edited by wysota; 21st March 2008 at 20:29. Reason: missing [code] tags

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

    Default Re: Can a QSqlModel be converted to a QStandardItemModel

    It might prove faster to subclass the sql model and add the functionality you need. What do you need the standard item model for?

  3. #3
    Join Date
    Aug 2007
    Posts
    29
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Can a QSqlModel be converted to a QStandardItemModel

    I need to be able to update the cells directly. Basically I can't have it read only. Yet I can't use the relationship model because the table relationships are too complex.

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

    Default Re: Can a QSqlModel be converted to a QStandardItemModel

    Maybe you could just make a view in your database and use QSqlTableModel to operate on it?

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.