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. table.selectRow no doing anything
Forum Update on Monday, May 27th 2025

table.selectRow no doing anything

Scheduled Pinned Locked Moved Unsolved Qt for Python
29 Posts 3 Posters 3.2k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #15

    That looks pretty convoluted. Can you explain why you remove the connection ?

    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
      PeterB74
      wrote on last edited by
      #16

      Because the backend library I use to process the necessary changes to the database is pure Python, so I need to release Qt's lock on the database first, have the Python library change the database, and then reload the database in Qt.

      JonBJ 1 Reply Last reply
      0
      • P PeterB74

        Because the backend library I use to process the necessary changes to the database is pure Python, so I need to release Qt's lock on the database first, have the Python library change the database, and then reload the database in Qt.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #17

        @PeterB74
        I will say this then: if you are saying you are actually using non-Qt Python stuff to execute the database updates/access I wonder why you are also trying to use QSqlDatabase at all? Maybe you should go via the Python level model? Closing and re-opening the connection/database/model is an "expensive" operation. Just a thought, I admit I don't know your full situation.

        1 Reply Last reply
        0
        • P Offline
          P Offline
          PeterB74
          wrote on last edited by
          #18

          I don't think replacing a fast C++ Qt direct database access with a slow Python wrapper is a good idea :-)

          Updates to the database happen relatively infrequently, but scrolling through it and filtering is very common.

          JonBJ 1 Reply Last reply
          0
          • P PeterB74

            I don't think replacing a fast C++ Qt direct database access with a slow Python wrapper is a good idea :-)

            Updates to the database happen relatively infrequently, but scrolling through it and filtering is very common.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by
            #19

            @PeterB74
            And you think the time taken to process the data in-memory in C++ versus in Python outweighs the time taken to access the data in the database across the library/protocol?

            Anyway, best of luck.

            1 Reply Last reply
            0
            • P Offline
              P Offline
              PeterB74
              wrote on last edited by
              #20

              The overhead of performing function calls in Python is very big because of the dynamical typing, and you need hundreds of calls to display a reasonable part of your table.

              I tried it out, and scrolling becomes unbearingly slow... Accessing the database while staying in C is way more efficient than C calling Python which then calls C again.

              JonBJ 1 Reply Last reply
              0
              • P PeterB74

                The overhead of performing function calls in Python is very big because of the dynamical typing, and you need hundreds of calls to display a reasonable part of your table.

                I tried it out, and scrolling becomes unbearingly slow... Accessing the database while staying in C is way more efficient than C calling Python which then calls C again.

                JonBJ Online
                JonBJ Online
                JonB
                wrote on last edited by
                #21

                @PeterB74
                Point taken! I can only say I used Python/PyQt to do SQL database read/writes/attached as model for Qt views and found it fine for large data (obviously with suitable paging for views if required). But I wasn't doing any Python<->C++ (other, of course, than what's going on in Qt C++ code).

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

                  One thing that intrigues me, why not just close the connection and reopen it after that ? It looks like there's no need to remove it completely. Or is the file trashed and recreated ?

                  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
                    PeterB74
                    wrote on last edited by
                    #23

                    If I only close the connection but otherwise leave my table intact, I'm getting into trouble because it seems there are still paint calls to my delegates, which require Qt database access...

                    But I guess I can add some logic to detect a closed database and return from the paint events without doing anything.

                    I'll have my user try out a version where I do that, thanks for the suggestion!

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

                      You can try QWidget's updatesEnabled property.

                      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
                        PeterB74
                        wrote on last edited by
                        #25

                        My user got back to me, still the same behaviour. selectRow simply refuses to do anything...

                        JonBJ 1 Reply Last reply
                        0
                        • P PeterB74

                          My user got back to me, still the same behaviour. selectRow simply refuses to do anything...

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by JonB
                          #26

                          @PeterB74
                          Ask user to debug the code for you? ;-)

                          Since you're not getting an answer here and it's only some certain situation/not readily reproducible, because it's Python can you quickly put in a bunch of print() or whatever statements, perhaps to a log file, for all possibly interesting places/values, and ask him to run your code?

                          BTW, could it be that user has some other/funny version of Qt or PyQt or something in his environment?

                          1 Reply Last reply
                          0
                          • P Offline
                            P Offline
                            PeterB74
                            wrote on last edited by
                            #27

                            To repeat what I mentioned higher in this thread, that is exactly what I'm doing: a debug statement right after the call to selectRow tells me that no row is selected.

                            Also, as I mentioned, the software is packaged with pyinstaller, so he has exactly the same environment for Python and Qt as me.

                            JonBJ 1 Reply Last reply
                            0
                            • P PeterB74

                              To repeat what I mentioned higher in this thread, that is exactly what I'm doing: a debug statement right after the call to selectRow tells me that no row is selected.

                              Also, as I mentioned, the software is packaged with pyinstaller, so he has exactly the same environment for Python and Qt as me.

                              JonBJ Online
                              JonBJ Online
                              JonB
                              wrote on last edited by
                              #28

                              @PeterB74
                              I meant maybe to be a bit more ambitious in what you try to print out. I don't know, maybe it's relevant to print out how many rows are in self.table.selectionModel().selectedRows()? Maybe it's relevant what the user does to get here?

                              Or, you can wait for someone here to figure out what is going on in your particular user case.

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                PeterB74
                                wrote on last edited by
                                #29

                                https://github.com/mnemosyne-proj/mnemosyne/issues/171

                                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