Results 1 to 2 of 2

Thread: QTableView is not refreshed

  1. #1
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default QTableView is not refreshed

    Hey @all,

    i've a problem with a subclass of a QSqlQueryModel.
    After I insert data into the database (SQLITE) and refresh the model, the view is not refreshed.
    Here the code of the subclass:
    Qt Code:
    1. MyModel::MyModel(QObject *parent) : QSqlQueryModel(parent) {
    2. // Innitialize the model
    3. refreshModel();
    4. }
    5.  
    6. void MyModel::addRecord() {
    7. QSqlQuery query;
    8. bool ok = query.exec("INSERT INTO ......");
    9. if(!ok) {
    10. QSqlError err;
    11. err = query.lastError();
    12. qDebug() << err.text();
    13. return;
    14. }
    15. refreshModel();
    16. }
    17.  
    18. QVariant MyModel::data(const QModelIndex &index, int role) const {
    19. if(index.isValid() && role == Qt::BackgroundRole) {
    20. QPalette palette;
    21.  
    22. // Alternating row color
    23. if(index.row() % 2 == 0)
    24. return palette.color(QPalette::Active, QPalette::Base);
    25. return palette.color(QPalette::Active, QPalette::AlternateBase);
    26. }
    27. return QSqlQueryModel::data(index, role);
    28. }
    29.  
    30. void MyModel::refreshModel() {
    31. clear();
    32. QSqlQueryModel::setQuery("SELECT field1, field2 field3, ....");
    33.  
    34. // Set the Header fields
    35. // ...
    36. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. m_ui->tableView->setModel(myModel);
    2. m_ui->tableView->hideColumn(0);
    3. m_ui->tableView->verticalHeader()->hide();
    4. m_ui->tableView->horizontalHeader()->hide();
    To copy to clipboard, switch view to plain text mode 

    The program never went into "if(!ok) {". In the debugger the refreshModel() is called, but the TableView isn't refreshed.

    Can anybody help?
    Thanks in advance

    Best Regards
    NoRulez

  2. #2
    Join Date
    Apr 2008
    Posts
    196
    Thanked 8 Times in 6 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    1

    Default Re: QTableView is not refreshed

    In the main program, I've used references instead of pointers.

    Thanks anyway

    Best Regards
    NoRulez

    How can i mark a thread as solved?

Similar Threads

  1. One Model, Two Views (QTreeView and QTableView)
    By dgarrett97 in forum Newbie
    Replies: 2
    Last Post: 14th September 2009, 18:10
  2. Replies: 2
    Last Post: 7th June 2009, 10:47
  3. Very high CPU usage with QTableView and MVC
    By montylee in forum Qt Programming
    Replies: 7
    Last Post: 24th March 2009, 06:14
  4. QTableView
    By dragon in forum Qt Programming
    Replies: 0
    Last Post: 22nd September 2008, 16:53
  5. Multi-line messages in QTableView
    By Conel in forum Qt Programming
    Replies: 6
    Last Post: 13th April 2006, 13:49

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.