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. Get content of cell from QTableView
Forum Updated to NodeBB v4.3 + New Features

Get content of cell from QTableView

Scheduled Pinned Locked Moved Solved General and Desktop
88 Posts 7 Posters 57.6k 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.
  • Karoluss96K Karoluss96

    @JonB said in Get content of cell from QTableView:

    Do you mean the code block I wrote a couple of posts ago above? You should be able to get that working so long as you do not yet have any None values in your data, have you tested that, does it work fully so long as no None values? Please answer!

    If I go through the all values (by tabs or putting blank space or one digit sign) code work without Exception!

    The problem is that there is no "sql's NULL" in Python, so we don't yet know what to do about Nones to get what we need across to SQL.
    If and when you confirm all is working from my code with no Nones involved, I will have a think about None/NULL. But not until you confirm my code works without Nones!

    That the main reason for all this discussion- how to auto-change None to NULL?!

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

    @Karoluss96 said in Get content of cell from QTableView:

    That the main reason for all this discussion- how to auto-change None to NULL?!

    I can give you some suggestions to try. But first I know you are using Python but not which Python binding you are using for Qt. It could be any of: PySide2, PyQt5, PySide6, PyQt6. Which one?

    1 Reply Last reply
    0
    • Karoluss96K Offline
      Karoluss96K Offline
      Karoluss96
      wrote on last edited by
      #79

      I suppose PyQt5

      as at beginng appears a line:

      from PyQt5.QtCore import QSettings
      
      JonBJ 1 Reply Last reply
      0
      • Karoluss96K Karoluss96

        I suppose PyQt5

        as at beginng appears a line:

        from PyQt5.QtCore import QSettings
        
        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #80

        @Karoluss96
        In place of the raise Exception(...) line try the following:

        1. val = None. If this works it would be simplest! It means that binding a None, does result in a NULL, so you can remove the special case completely.

        2. val = QVariant(). Try this next. You may find you need a from PyQt5.QtCore import QVariant statement at the head of the file near the other PyQt5 imports.

        If #2 does not work I would be interested to know if you get an error message anywhere (e.g. perhaps on the query.exec_()) and what the message says.

        1 Reply Last reply
        0
        • Karoluss96K Offline
          Karoluss96K Offline
          Karoluss96
          wrote on last edited by
          #81

          Well... that all makes (and maybe also you) me tired. My chef will help me with this...

          If finally works I'll informe you!

          JonBJ 1 Reply Last reply
          0
          • Karoluss96K Karoluss96

            Well... that all makes (and maybe also you) me tired. My chef will help me with this...

            If finally works I'll informe you!

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

            @Karoluss96
            Did you not just try those two? Having spent this much time I am keen to know now...!

            1 Reply Last reply
            0
            • Karoluss96K Offline
              Karoluss96K Offline
              Karoluss96
              wrote on last edited by
              #83

              Well... I tried, but I won't to answer it's correct or not as the code with previous versions become messy.

              I saw that you're solved a little problem here: https://forum.qt.io/topic/90363/inexplicable-qsqlquerymodel-handling-of-null-value/14

              JonBJ 1 Reply Last reply
              0
              • Karoluss96K Karoluss96

                Well... I tried, but I won't to answer it's correct or not as the code with previous versions become messy.

                I saw that you're solved a little problem here: https://forum.qt.io/topic/90363/inexplicable-qsqlquerymodel-handling-of-null-value/14

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

                @Karoluss96
                That is so long ago I barely remember! Except that I didn't feel I got much from the PyQt author/mailing list :(

                In the last post there a guy says:

                though Oracle treats empty strings as NULL

                You seem to be using PLSQL. So another thing to try, if no joy from my previous two suggestions, might be val = "" for the None case if that really is true.

                1 Reply Last reply
                0
                • Karoluss96K Offline
                  Karoluss96K Offline
                  Karoluss96
                  wrote on last edited by
                  #85

                  Yes, but now I try by my chef's suggestions with a little returing for a starting point.
                  I'll answer if finally goes... or returning to your version if doesn't go

                  1 Reply Last reply
                  0
                  • Karoluss96K Offline
                    Karoluss96K Offline
                    Karoluss96
                    wrote on last edited by
                    #86

                    After a long fight my chef find the working answer:

                    for col in range(model.columnCount()):
                                rowData = [model.index(row, col).data() for col in range(model.columnCount()) ]
                       
                                letersBind = [':a',':bb',':bc',':bd',':be',':bf',':bg',':bh',':bi',':bj',':bk',':bl',':bm',':bn',':bo',':bp',':cba',':cbb',':cbc',':cbd',
                                              ':cbe',':cbf',':cbg',':cbh',':cbi',':cbj',':cbk',':cbl',':cbn',':cbo',':cbp',':cca',':ccb',':ccc']    
                                if rowData[col] is None:
                                    query.addBindValue('')
                                    print(col,' 1')
                                else:
                                    query.bindValue(letersBind[col],rowData[col])
                            
                            query.exec_()
                            print (query.lastError().text())
                            while query.next():
                                self.model4.insertRow(row)   
                    

                    I' don't from what come the letters, which exchange the ? singns in () for Values

                    JonBJ 1 Reply Last reply
                    0
                    • Karoluss96K Karoluss96

                      After a long fight my chef find the working answer:

                      for col in range(model.columnCount()):
                                  rowData = [model.index(row, col).data() for col in range(model.columnCount()) ]
                         
                                  letersBind = [':a',':bb',':bc',':bd',':be',':bf',':bg',':bh',':bi',':bj',':bk',':bl',':bm',':bn',':bo',':bp',':cba',':cbb',':cbc',':cbd',
                                                ':cbe',':cbf',':cbg',':cbh',':cbi',':cbj',':cbk',':cbl',':cbn',':cbo',':cbp',':cca',':ccb',':ccc']    
                                  if rowData[col] is None:
                                      query.addBindValue('')
                                      print(col,' 1')
                                  else:
                                      query.bindValue(letersBind[col],rowData[col])
                              
                              query.exec_()
                              print (query.lastError().text())
                              while query.next():
                                  self.model4.insertRow(row)   
                      

                      I' don't from what come the letters, which exchange the ? singns in () for Values

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

                      @Karoluss96 said in Get content of cell from QTableView:

                      After a long fight my chef find the working answer:

                              if rowData[col] is None:
                                  query.addBindValue('')
                      

                      @JonB said in Get content of cell from QTableView:

                      You seem to be using PLSQL. So another thing to try, if no joy from my previous two suggestions, might be val = "" for the None case if that really is true.

                      1 Reply Last reply
                      0
                      • Karoluss96K Offline
                        Karoluss96K Offline
                        Karoluss96
                        wrote on last edited by
                        #88

                        Thanks for all helping!

                        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