[SOLVED]Setting current row in QSqlTableModel



  • Hi,

    Could you please guide me how can I set the current row in QSqlTableModel?

    PS
    I've QTableView and QComboBox both of them attached to same QSqlTableModel I want to set the current row in QTableView dependeing on selected index in QComboBox. I can get the selected index in QComboBox through currentIndexChanged(int index) slot but I don't know to set the current in QSqlTableModel.

    @void MainWindow::on_comboBox_find_currentIndexChanged(int index)
    {
    if (p_db.isOpen()) {
    //! \bug doesn't select the row although the index is correct!
    if (p_tableModel->selectRow(index)) {
    qDebug() << index;
    }
    }
    }@



  • Voila, I fixed it.

    @void MainWindow::on_comboBox_find_currentIndexChanged(int index)
    {
    if (p_db.isOpen()) {
    if (p_tableModel->selectRow(index)) {
    ui->tableView_table->setCurrentIndex(p_tableModel->index(index, 0));
    qDebug() << index;
    }
    }
    }@


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.