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. Editable QSQLQueryModel behaves different in Qt 5.7 then in Qt 5.4
Forum Updated to NodeBB v4.3 + New Features

Editable QSQLQueryModel behaves different in Qt 5.7 then in Qt 5.4

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 2 Posters 3.1k 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.
  • HikaruTakahashiH Offline
    HikaruTakahashiH Offline
    HikaruTakahashi
    wrote on last edited by HikaruTakahashi
    #1

    Hello everyone, maybe some one can help with some explaination. Recently I migrated my applications from qt 5.4.1 to Qt 5.7.0. Everything works fine except one thing.

    I use a editable Qsqlquerymodel. The implementation is based on the example [http://doc.qt.io/qt-5/qtsql-querymodel-example.html](link url).

    In my applications i hide most time some columns, and this seems to make problems in Qt5.7. When I now edit a element in the tableview, the edit works as expected, but the hidden column comes visible again.

    here an example how to reproduce
    That is how I set the model:

    	editableModel = new EditableSqlModel(this);
    	editableModel->setDBConnectionInfo(hostname, port, databaseName, userName, password, connectionBaseName, sessionWorkUpID);
    	TestView = findChild<QTableView*>("TestView");
    	TestView->setModel(editableModel);
    	editableModel->refresh();
    	TestView->hideColumn(0);
    

    The editableModel is the code from the example (to make it easier to reproduce).

    Now I know the model emits modelReset(). So I tried connecting on it, to hide the column again. But on a large amount of data this is noticable by the user (as the user can see for a short time the popping up of the column before it gets hidden again).

    And the other problem is also all section resize section are going away after editing, so things set like this:

    	TestView->horizontalHeader()->resizeSection(1, 30);
    	TestView->horizontalHeader()->resizeSection(2, 130);
    	TestView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
    	TestView->horizontalHeader()->setSectionResizeMode(1, QHeaderView::Fixed);
    

    Here the Problem is that when reacting to modelReset() Signal it seems to early to reset this header stuff, I didn't find the right place.

    But I do not understand why this is happening, because in Qt5.4 this code works without the described strange behavior. Maybe I missed something to change.

    I would be glad if anyone could give hint how to solve this problems.

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

      Hi and welcome to devnet,

      Not a direct answer, but do you really need to do a model reset ? Or what is triggering that reset ?

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

      HikaruTakahashiH 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi and welcome to devnet,

        Not a direct answer, but do you really need to do a model reset ? Or what is triggering that reset ?

        HikaruTakahashiH Offline
        HikaruTakahashiH Offline
        HikaruTakahashi
        wrote on last edited by
        #3

        @SGaist The modelReset is triggered after setData() was called in the model. This happens with and without set delegates.

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

          After a call to setData ? That's pretty unusual.

          Why do you need to reset your model ?

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

          HikaruTakahashiH 1 Reply Last reply
          0
          • SGaistS SGaist

            After a call to setData ? That's pretty unusual.

            Why do you need to reset your model ?

            HikaruTakahashiH Offline
            HikaruTakahashiH Offline
            HikaruTakahashi
            wrote on last edited by HikaruTakahashi
            #5

            @SGaist I do not call directly setData() nor resetModel(), it is called by Qt after leaving the editmode. This happens the same in the Qt Example (link posted above), so I assumed that this is normal intended behavior.

            Maybe the example of Qt is misleading or incorrect then. But I do not know how to implement it then, because in Qt 5.4 the same code worked as expected (hidden columns didn't pop up unexpected, and resizemodes set on the headerview didn't reset).

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

              Ok, that doesn't sound like the correct behavior. Might be a regression.

              Can you point the example you are using for that ?

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

              HikaruTakahashiH 1 Reply Last reply
              0
              • SGaistS SGaist

                Ok, that doesn't sound like the correct behavior. Might be a regression.

                Can you point the example you are using for that ?

                HikaruTakahashiH Offline
                HikaruTakahashiH Offline
                HikaruTakahashi
                wrote on last edited by HikaruTakahashi
                #7

                @SGaist I used the example http://doc.qt.io/qt-5/qtsql-querymodel-example.html

                I just used the files editablesqlmodel.cpp and editablesqlmodel.h from the example, moved the function refresh() to public section and call the class following way:

                /* instance of class contained in editablesqlmodel.h/cpp*/
                editableModel = new EditableSqlModel(this); 
                
                /* connecting to my database where a table person is existing with some example data as used in the example*/
                editableModel->setDBConnectionInfo(hostname, port, databaseName, userName, password, connectionBaseName, sessionWorkUpID); 
                
                /* connected to modelReset() just to see when it is called */
                connect(editableModel, SIGNAL(modelReset()), this, SLOT(slot_modelResetTest()));
                
                /* get the pointer to QTableView instance from my ui file */
                TestView = findChild<QTableView*>("TestView");
                
                /* set the model to the view */
                TestView->setModel(editableModel);
                
                /* initialize the model with the testdata from the database */
                editableModel->refresh();
                
                /* hide first column (ID column in database) */
                TestView->hideColumn(0);
                

                When now triggered in the editmode in the by double click on a cell in the table slot_modelResetTest() is called after leaving the editmode (by clicking somewhere else).

                1 Reply Last reply
                0
                • HikaruTakahashiH Offline
                  HikaruTakahashiH Offline
                  HikaruTakahashi
                  wrote on last edited by HikaruTakahashi
                  #8

                  I think I found the problem.

                  In the implemenation of the example in editablesqlmodel.cpp function setData(), the function clear() is called.

                  When I comment out the clear() call, everything works as expected. Editing, Insertion, Deletion works now fine, hidden columns stay hidden, and the resizemode of the sections in the header stay as configured at begin.

                  But I am not sure if this may have some side effects. The documentation of Qt is not very clear in this case to me (Documentation of clear() function in QSqlQueryModel).

                  Maybe someone can explain it a little bit more to me.

                  I will test the model some time, if I am satified I will mark this question as solved.

                  EDIT: @SGaist thanks for helping so much, your right questions leaded to the solution ;-)

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

                    See QTBUG-49404 for more information about what has changed.

                    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

                    • Login

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