Results 1 to 10 of 10

Thread: Why does the last row remain in QTableView until the page is reloaded ?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2016
    Location
    U.K.
    Posts
    16
    Thanks
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Why does the last row remain in QTableView until the page is reloaded ?

    Hi All,

    I'm using [Qt] QTableView and QSqlQueryModel with SQLite Database, I'm trying to delete rows from the QTableView(from the database) by clicking on a row which opens up another page where I carry out the deletion and using 'emit' signal and slot to update the parent page, it all works fine till the VERY LAST ROW. It deletes from the database but remains in the
    QTableView until I reload the page, why ?

    Qt Code:
    1. while(qry.next())
    2. {
    3. QSqlQueryModel *model = new QSqlQueryModel(ui->tableView_staffLog);
    4. model->setQuery(qry);
    5. model->setHeaderData(0, Qt::Horizontal, QObject::tr("ID"));
    6. model->setHeaderData(1, Qt::Horizontal, QObject::tr("Name"));
    7. model->setHeaderData(2, Qt::Horizontal, QObject::tr("Depart"));
    8. model->setHeaderData(3, Qt::Horizontal, QObject::tr("Car Reg"));
    9. model->setHeaderData(4, Qt::Horizontal, QObject::tr("Srt Date"));
    10. model->setHeaderData(5, Qt::Horizontal, QObject::tr("End Date"));
    11. model->setHeaderData(6, Qt::Horizontal, QObject::tr("Contact"));
    12. model->setHeaderData(7, Qt::Horizontal, QObject::tr("Photo"));
    13. ui->tableView_staffLog->setModel(model);
    14. }
    15. connect(ui->tableView_staffLog, SIGNAL(pressed(const QModelIndex&)), this,
    16. SLOT(on_tableView_staffLog_clicked(const QModelIndex&)));
    17. }
    18. void ControlPanel::on_tableView_staffLog_clicked(const QModelIndex& index)
    19. {
    20. const QAbstractItemModel* tableModel = ui->tableView_staffLog->model();
    21. int emp_id = tableModel->data(tableModel->index(index.row(),0), Qt::DisplayRole).toInt();
    22.  
    23. employeedetails = EmployeeDetails::instance(emp_id, index.row(), this);
    24. connect( employeedetails, SIGNAL(employeeDeleted(int)), this, SLOT(deleteEmployee(int)) );
    25. employeedetails->show();
    26. }
    To copy to clipboard, switch view to plain text mode 

    Child page
    Qt Code:
    1. query.prepare("UPDATE employee SET is_hidden = '1' WHERE emp_id = (:emp_id)");
    2. query.bindValue(":emp_id", emp_id);
    3. success = query.exec();
    4. if(!success)
    5. {
    6. qDebug() << "removeEmployee error: "
    7. << query.lastError();
    8. }
    9. else
    10. {
    11. if( tableRow >= 0 )
    12. emit employeeDeleted(tableRow);
    13. this->close();
    14. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by zed220; 10th August 2017 at 10:06.

Similar Threads

  1. Replies: 3
    Last Post: 20th February 2018, 14:55
  2. qtableview multiply page support
    By tdm in forum Newbie
    Replies: 1
    Last Post: 1st March 2017, 04:41
  3. Symbols remain after running strip
    By ScottBell in forum Qt Tools
    Replies: 0
    Last Post: 7th November 2011, 03:30
  4. Compiling QT programs in Visual C++ 2008 by including batch files, reloaded projects
    By Meek the Geek in forum Installation and Deployment
    Replies: 6
    Last Post: 12th July 2010, 20:11
  5. QMenu: remain visible while mouseOver
    By vonCZ in forum Newbie
    Replies: 10
    Last Post: 25th October 2007, 16:54

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.