Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED]Setting current row in QSqlTableModel
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]Setting current row in QSqlTableModel

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbnoimi
    wrote on last edited by
    #1

    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;
    }
    }
    }@

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbnoimi
      wrote on last edited by
      #2

      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;
      }
      }
      }@

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved