Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QSqlTableModel(): Add an empty record with an auto-increment column
QtWS25 Last Chance

QSqlTableModel(): Add an empty record with an auto-increment column

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 1 Posters 191 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.
  • P Offline
    P Offline
    PythonQTMarlem
    wrote on last edited by
    #1

    Hello,
    the first column of my table is auto-increment.
    I want to add an empty record to the end of the table.

    Here is my attempt:

    def add_record(self):
            record = self.table_model.record()
            record.setValue(self.table_model.rowCount()+1, '','','')
            self.table_model.insertRecord(self.table_model.rowCount(), record)
    

    When executed, the program crashes with the following error message:
    Process finished with exit code -1073740791 (0xC0000409)

    Question:
    How does it work without a program crash?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      PythonQTMarlem
      wrote on last edited by
      #2

      sorry, it is easy:

          def datensatz_hinzufuegen(self):
              self.table_model.insertRow(self.table_model.rowCount())
      
      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