Results 1 to 1 of 1

Thread: [solved]My SqlModel and refresh view

  1. #1
    Join Date
    Oct 2010
    Location
    Poland
    Posts
    26
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default [solved]My SqlModel and refresh view

    I have a model - yes is not very elegant but I need class like this:
    Qt Code:
    1. class MySqlModel : public QAbstractTableModel
    2. {
    3. public:
    4. /*
    5. there are all methods needed by model like
    6. rowCount, columnCount, data ...
    7. */
    8.  
    9. bool insert( const QSqlRecord& rec );
    10.  
    11. protected:
    12. QSqlQuery* query;
    13. }
    To copy to clipboard, switch view to plain text mode 

    All methods are redirect to model like:

    Qt Code:
    1. int MySqlModel::rowCount(const QModelIndex &parent) const
    2. {
    3. return model->rowCount();
    4. }
    To copy to clipboard, switch view to plain text mode 

    I'm making insert to table by method which looks like that:

    Qt Code:
    1. bool MySqlModel::insert( const QSqlRecord& rec )
    2. {
    3. query->prepare( insertQuery );
    4. if( query->exec() )
    5. {
    6.  
    7. // here I want to refresh a view
    8. // I remove this -> emit dataChanged( QModelIndex(), QModelIndex() ); // nothing happens :(
    9.  
    10. // this methods resolved my issue
    11. beginInsertRows( QModelIndex(), 0, 0 );
    12. endInsertRows();
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    How I should update view? I create view like this:
    Qt Code:
    1. view->setModel( model ); // model it is MySqlModel and data are in view after this operation - view is a standard QTableView
    To copy to clipboard, switch view to plain text mode 

    Solution I describe in listening with insert method.
    Last edited by Hostel; 15th September 2011 at 23:21. Reason: updated contents

Similar Threads

  1. How to get row no in sqlmodel
    By raju@123 in forum Qt Programming
    Replies: 1
    Last Post: 16th October 2010, 08:06
  2. Replies: 3
    Last Post: 18th March 2010, 04:49
  3. How to constantly refresh time on a view
    By salmanmanekia in forum Qt Programming
    Replies: 5
    Last Post: 23rd June 2008, 12:44
  4. [model/view] slow refresh on big table
    By lauranger in forum Qt Programming
    Replies: 4
    Last Post: 3rd March 2008, 21:40
  5. Replies: 9
    Last Post: 7th November 2006, 15:10

Tags for this Thread

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.