Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Call for Presentations - Qt World Summit

    Solved QSqlTableModel removeRow() not removing records from some tables ?

    General and Desktop
    qsqltablemodel sqlite database qsqlite
    3
    5
    169
    Loading More Posts
    • 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.
    • R
      R-P-H last edited by R-P-H

      Hi,

      I am using a SQLite database. When trying to remove records from some tables; the records are not removed. In the table the record remains although at the bottom it says 1-0 of 1 records. Using the exact same code on a different table it works fine. What could be the issue with removing records from some of these tables ?

      QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
      db.setDatabaseName("myDB");
      
      QSqlTableModel *model = new QSqlTableModel;
      model->setTable("myTable");
      model->select();
      model->removeRow(0); //Remove row 0.
      
      1 Reply Last reply Reply Quote 0
      • Christian Ehrlicher
        Christian Ehrlicher Lifetime Qt Champion last edited by

        Compare your tables (I would guess your non-working table has no PK) and / or provide a minimal, compilable examples.
        Without the tables and some code we can't see what might go wrong.

        Qt has to stay free or it will die.

        artwaw R 2 Replies Last reply Reply Quote 3
        • Christian Ehrlicher
          Christian Ehrlicher Lifetime Qt Champion last edited by

          Compare your tables (I would guess your non-working table has no PK) and / or provide a minimal, compilable examples.
          Without the tables and some code we can't see what might go wrong.

          Qt has to stay free or it will die.

          artwaw R 2 Replies Last reply Reply Quote 3
          • artwaw
            artwaw @Christian Ehrlicher last edited by artwaw

            @Christian-Ehrlicher I don't believe it is possible to have sqlite with no primary key (the rowid column is always created unless explicitly declared with no rowid but then if no other pk is present this should fail).

            @R-P-H please post your code and tables definitions, otherwise we're just whistling in the dark.

            For more information please re-read.

            Kind Regards,
            Artur

            1 Reply Last reply Reply Quote 2
            • R
              R-P-H @Christian Ehrlicher last edited by

              @Christian-Ehrlicher said in QSqlTableModel removeRow() not removing records from some tables ?:

              Compare your tables (I would guess your non-working table has no PK) and / or provide a minimal, compilable examples.
              Without the tables and some code we can't see what might go wrong.

              @Christian-Ehrlicher Thanks, adding a primary key to the tables solved the issue. The tables did have a built in rowid column but it looks like Qt requires a user-defined PK column for it to work.

              1 Reply Last reply Reply Quote 0
              • Christian Ehrlicher
                Christian Ehrlicher Lifetime Qt Champion last edited by

                The QSqlTableModel needs a real PK, yes.

                Qt has to stay free or it will die.

                1 Reply Last reply Reply Quote 2
                • First post
                  Last post