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. QSqlTableModel problem with set data

QSqlTableModel problem with set data

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsqltablemodelqsqlite
4 Posts 2 Posters 1.9k Views
  • 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.
  • XardasX Offline
    XardasX Offline
    Xardas
    wrote on last edited by
    #1
    db = QSqlDatabase::addDatabase("QSQLITE");
    db.setDatabaseName("test.db");
    db.open();
    QSqlQuery q(db);
    q.prepare("CREATE TABLE IF NOT EXISTS test(id INTEGER PRIMARY KEY AUTOINCREMENT, Date_O VARCHAR(255));");
    q.exec();
    model = new QSqlTableModel(this, db);
    model->setTable("test");
    model->setEditStrategy(QSqlTableModel::OnFieldChange);
    model->select();
    ui.tableView->setModel(model);
    connect(ui.add_b, &QPushButton::clicked, [&](){model->insertRow(0); });
    

    After few clicks on button inserted only one row
    ++ after edit fields data is not stored in table.
    What could be the problem?

    Thanks in advance!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      For newly added row, OnFieldChange behaves like OnRowChange. See more information here.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      XardasX 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        For newly added row, OnFieldChange behaves like OnRowChange. See more information here.

        XardasX Offline
        XardasX Offline
        Xardas
        wrote on last edited by
        #3

        @SGaist thanks for reply,
        but, how i can insertRow row with AUTOINCREMENT ?
        example, insertRow() -> insert empty row with AUTO INCREMENT ID.
        is it possible without reimplementation?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Either trigger the submit yourself or fill all fields in the row.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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