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. Model / View update base
QtWS25 Last Chance

Model / View update base

Scheduled Pinned Locked Moved Solved Qt for Python
6 Posts 3 Posters 463 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.
  • D Offline
    D Offline
    dw06
    wrote on last edited by
    #1

    Good morning,

    I'm exploring QT Python and PySide6

    I have a problem understanding the Model / view
    I study the Book example
    [https://doc.qt.io/qtforpython-6/examples/example_sql_books.html](link url)
    the table view works: the data displayed is modified but the sqlite database is not updated (I replaced the memory base with a disk base)
    I thought I understood, by reading the documentation, that when the model was modified, the database was updated automatically.
    Can you give me a start?
    thanks in advance

    1 Reply Last reply
    0
    • JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      Glancing at the code, so far as I can see I would expect it to work for a file if you just replace memory with that. How did you specify the file (full path rather than relative would be advisable). Did you create it first or leave SQLite to create it on first access?

      1 Reply Last reply
      0
      • D Offline
        D Offline
        dw06
        wrote on last edited by dw06
        #3

        Thank you for your interest.
        I just changed these 2 lines...in createdb.py

        db.setDatabaseName("D:/Do-asus_Data/Documents/prjPython/TestQT/books/test.db")
        # db.setDatabaseName(":memory:")

        The file database does not exist at the start of the programme.
        I left the year field by "enter" and "mouse click on another field". In no case has the database been updated.
        The database test.db opened with DB Browser allows the year field of the book table to be updated.

        SGaistS 1 Reply Last reply
        0
        • D dw06

          Thank you for your interest.
          I just changed these 2 lines...in createdb.py

          db.setDatabaseName("D:/Do-asus_Data/Documents/prjPython/TestQT/books/test.db")
          # db.setDatabaseName(":memory:")

          The file database does not exist at the start of the programme.
          I left the year field by "enter" and "mouse click on another field". In no case has the database been updated.
          The database test.db opened with DB Browser allows the year field of the book table to be updated.

          SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @dw06 hi,

          Based on a quick look at the code, the submit is configured to only happen on manual submit but nothing in your code seems to be doing that.

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

          JonBJ 1 Reply Last reply
          1
          • SGaistS SGaist

            @dw06 hi,

            Based on a quick look at the code, the submit is configured to only happen on manual submit but nothing in your code seems to be doing that.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #5

            @SGaist
            ..and indeed the OP's Python-only SQL Books Example has OnManualSubmit and no submit...()...

            @dw06
            This is not your fault! Because the example used memory I guess no one noticed it never actually wrote back to the database!
            Go look up the submit stuff in the docs and either make it one of the submit-as-you-move or do a submitAll() somewhere.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              dw06
              wrote on last edited by
              #6

              Thanks to you two,
              I changed the "QSqlTableModel.OnManualSubmit" to QSqlTableModel.OnRowChange" now it's OK The database is updated.

              1 Reply Last reply
              2
              • D dw06 has marked this topic as solved on

              • Login

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