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 removeRow() not removing records from some tables ?

QSqlTableModel removeRow() not removing records from some tables ?

Scheduled Pinned Locked Moved Solved General and Desktop
qsqltablemodelsqlitedatabaseqsqlite
5 Posts 3 Posters 717 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.
  • R Offline
    R Offline
    R-P-H
    wrote on last edited by R-P-H
    #1

    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
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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 Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      artwawA R 2 Replies Last reply
      3
      • Christian EhrlicherC Christian Ehrlicher

        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.

        artwawA Offline
        artwawA Offline
        artwaw
        wrote on last edited by artwaw
        #3

        @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
        2
        • Christian EhrlicherC Christian Ehrlicher

          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.

          R Offline
          R Offline
          R-P-H
          wrote on last edited by
          #4

          @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
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            The QSqlTableModel needs a real PK, yes.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2

            • Login

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