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
QtWS25 Last Chance

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.
  • X Offline
    X Offline
    Xardas
    wrote on 28 Jul 2016, 17:52 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 28 Jul 2016, 22:24 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

      X 1 Reply Last reply 29 Jul 2016, 11:30
      0
      • S SGaist
        28 Jul 2016, 22:24

        Hi,

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

        X Offline
        X Offline
        Xardas
        wrote on 29 Jul 2016, 11:30 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 29 Jul 2016, 21:44 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

          1/4

          28 Jul 2016, 17:52

          • Login

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