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. How to insert new record in a QSqlRelationalTableModel
Forum Updated to NodeBB v4.3 + New Features

How to insert new record in a QSqlRelationalTableModel

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 4 Posters 1.2k Views 1 Watching
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    What happens if you manually call submit on the mapper ?

    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
    1
    • P Offline
      P Offline
      Panoss
      wrote on last edited by Panoss
      #5

      The same: a new record is created but only the autoincremented field is filled, the others are empty, null.
      I tried mapper->submit() and model->submitAll().

      Maybe it's because mapping is happening in the constructor of the form? And the controls on the form have not yet been fully created?

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #6

        Are you sur the mapper is valid ?
        Why is it not part of your dialog rather than passed around ?

        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
        • P Offline
          P Offline
          Panoss
          wrote on last edited by Panoss
          #7

          The mapper is created in the parent form.
          It 's passed to the child (addArticle).
          I want to use it in the child for inserting a new record.

          How can I check if it's valid?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #8

            Check the current index.

            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
            • P Offline
              P Offline
              Panoss
              wrote on last edited by
              #9

              mapper 's currentIndex works ok, so I guess the mapper is valid.

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #10

                Your record is empty - so what's your db structure. Does it allow NULL values, has it a PK?

                P 1 Reply Last reply
                1
                • Christian EhrlicherC Christian Ehrlicher

                  Your record is empty - so what's your db structure. Does it allow NULL values, has it a PK?

                  P Offline
                  P Offline
                  Panoss
                  wrote on last edited by Panoss
                  #11

                  The table does have a primary key.
                  The record gets inserted in the database, so I guess it allows NULL values.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      gillranjeett
                      wrote on last edited by gillranjeett
                      #13

                      I want to use it in the child for inserting a new record. mx player for pc mxplayer

                      1 Reply Last reply
                      0
                      • SGaistS Offline
                        SGaistS Offline
                        SGaist
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        The logic should be the other way around.
                        Use the dialog to get the data from your application user. Then create the record based on the data you extract from the dialog.
                        This will also allow you to properly handle cancellation of the dialog. Otherwise you may end up with empty rows in the database that you will need to remove because you added it too early in your business logic.

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

                        P 1 Reply Last reply
                        1
                        • SGaistS SGaist

                          The logic should be the other way around.
                          Use the dialog to get the data from your application user. Then create the record based on the data you extract from the dialog.
                          This will also allow you to properly handle cancellation of the dialog. Otherwise you may end up with empty rows in the database that you will need to remove because you added it too early in your business logic.

                          P Offline
                          P Offline
                          Panoss
                          wrote on last edited by
                          #15

                          @SGaist said in How to insert new record in a QSqlRelationalTableModel:

                          Use the dialog to get the data from your application user. Then create the record based on the data you extract from the dialog.

                          I 'll do it this way.

                          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