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. SQL Widget Mapper Example Weirdness
Forum Updated to NodeBB v4.3 + New Features

SQL Widget Mapper Example Weirdness

Scheduled Pinned Locked Moved General and Desktop
sqlqt5.5
11 Posts 3 Posters 3.8k Views 3 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.
  • mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #2

    Hi
    Very good description.

    I tried the sample. I get same result as you. It does not
    save the change of addresstype.
    If I change address ,the changed address is saved.

    I changed the database from memory to file and looked in it.
    the typeid field is never updated.
    So it seems that this
    model->setRelation(typeIndex, QSqlRelation("addresstype", "id", "description"));

    is not really working as expected.

    kshegunovK 1 Reply Last reply
    2
    • mrjjM mrjj

      Hi
      Very good description.

      I tried the sample. I get same result as you. It does not
      save the change of addresstype.
      If I change address ,the changed address is saved.

      I changed the database from memory to file and looked in it.
      the typeid field is never updated.
      So it seems that this
      model->setRelation(typeIndex, QSqlRelation("addresstype", "id", "description"));

      is not really working as expected.

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #3

      @mrjj said:

      I changed the database from memory to file and looked in it.

      Because model->submit() is never called. Note that in the example the submit strategy is set to manual:

      model->setEditStrategy(QSqlTableModel::OnManualSubmit);
      

      in void Window::setupModel(). Still the model data should be updated at least to the point where it's visible in the UI. Possibly this is a bug, however I haven't the time right now to download and run the example, maybe this evening I'll try and report my findings.

      Read and abide by the Qt Code of Conduct

      mrjjM 1 Reply Last reply
      1
      • kshegunovK kshegunov

        @mrjj said:

        I changed the database from memory to file and looked in it.

        Because model->submit() is never called. Note that in the example the submit strategy is set to manual:

        model->setEditStrategy(QSqlTableModel::OnManualSubmit);
        

        in void Window::setupModel(). Still the model data should be updated at least to the point where it's visible in the UI. Possibly this is a bug, however I haven't the time right now to download and run the example, maybe this evening I'll try and report my findings.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #4

        @kshegunov
        Hi
        Thanks for input.
        But it does indeed save address changes?
        And I also tried with setEditStrategy to Row for test.

        Would be great if u in evening could have and tell if U see same results.

        kshegunovK 1 Reply Last reply
        1
        • mrjjM mrjj

          @kshegunov
          Hi
          Thanks for input.
          But it does indeed save address changes?
          And I also tried with setEditStrategy to Row for test.

          Would be great if u in evening could have and tell if U see same results.

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #5

          @mrjj

          But it does indeed save address changes?

          It should, just not flushing them to the SQL database.

          Would be great if u in evening could have and tell if U see same results.

          I'll try!

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          1
          • J Offline
            J Offline
            JoeB
            wrote on last edited by
            #6

            Wow thanks for the quick replies!

            I hadn't thought to check the edit strategy of the sample code. Still, if this was all working as expected, the comboBox should update to either the old setting (if unsaved) or the new setting (if saved), but in practice it can be made to show the third, unaffected option.

            I didn't check the edit strategy, or the underlying status of the SQL database, because in my own code, I have a similar architecture which uses the OnFieldChange edit strategy and quick access to the underlying database. Using the same techniques, I can say that the changes -are- occurring as expected everywhere but in the visual component of the comboBox.

            For example:
            Data from the main table, Item, fills every other mapped widget correctly. Before any changes are made, it correctly relates the id to the Vendor table's relevant column, name, and correctly sets the text or index (I'm still not sure which of these it's using to find the entry) of the comboBox to match that related entry.

            After selecting a differing item from the comboBox, the correct change has been made. Specifically, the vendorID (related id) in the Item table has changed to the appropriate id from the Vendor table, through the visibly related name. No incorrect changes are made to other Item table data, nor is the Vendor table data modified at all. Honestly, if I could be satisfied forcing the window to close after making a change here, the whole process could be considered to be working perfectly.

            I have noticed that normally the comboBox will trigger both the currentIndexChanged and currentTextChanged slots when the QDataWidgetMapper runs toNext() and toPrevious(). Once the comboBox has been changed, however, it stops triggering either of these slots on any subsequent navigation to that entry in the model through those methods. I haven't tested this on the example, but I suspect a similar outcome.

            Hope that helps. I can dump my own code for review if necessary, but don't believe it varies very meaningfully from the example.

            1 Reply Last reply
            0
            • kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #7

              @JoeB, @mrjj
              I run that example on all my currently available Qt versions (5.5, 5.6 and the dev branch) and it's not working as expected on any of them. However seeing the behavior first I'd assume that there's something wrong with the example itself before going to the library code. Unfortunately, I haven't seen anything wrong with it, so I'm currently debugging the mapper widget. As investigations continue any finds I'll report here promptly.

              Read and abide by the Qt Code of Conduct

              1 Reply Last reply
              2
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Thank you.

                kshegunovK 1 Reply Last reply
                1
                • mrjjM mrjj

                  Thank you.

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by kshegunov
                  #9

                  Well, it definitely seems like a bug. I muddled through some of the source and it does seem that the mapper sets the data correctly, at least as far as I can see in the debugger. My suspicion is that loading it back is broken for the combo box ...
                  @JoeB, my suggestion is to file a bug report (I believe you could login with your forum credentials) and hopefully someone more versed in the internals would fix that up. Or even if you can you could try and fix it and submit your patch for review (eventually it should get integrated into the main branch). That's all from me for now.

                  Kind regards.

                  Read and abide by the Qt Code of Conduct

                  1 Reply Last reply
                  2
                  • J Offline
                    J Offline
                    JoeB
                    wrote on last edited by
                    #10

                    I believe filing the bug report is the best course of action for my experience level. Thank you to everyone who replied. If there is an upvote or recommendation system that I'm missing, let me know so I can log my praise officially, and if I need to do anything further to make this question as answered, I can't find it. Thanks again.

                    kshegunovK 1 Reply Last reply
                    0
                    • J JoeB

                      I believe filing the bug report is the best course of action for my experience level. Thank you to everyone who replied. If there is an upvote or recommendation system that I'm missing, let me know so I can log my praise officially, and if I need to do anything further to make this question as answered, I can't find it. Thanks again.

                      kshegunovK Offline
                      kshegunovK Offline
                      kshegunov
                      Moderators
                      wrote on last edited by
                      #11

                      @JoeB
                      You can give reputation points (the stars next to the name) by clicking on the up arrow or take such points by using the down arrow (for each post). You can bookmark posts with the favourite button. You mark the thread as solved by going down to the bottom, clicking the Topic tools button and selecting Mark as solved.

                      Read and abide by the Qt Code of Conduct

                      1 Reply Last reply
                      1

                      • Login

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