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. QSqlQueryModel.setQuery() won´t accept strg
Forum Updated to NodeBB v4.3 + New Features

QSqlQueryModel.setQuery() won´t accept strg

Scheduled Pinned Locked Moved Solved Qt for Python
qt for pythonpyside
5 Posts 2 Posters 130 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.
  • S Offline
    S Offline
    SeamusQDraide
    wrote last edited by
    #1

    Hi everyone!

    I have a problem handing over the query to the setQuery() function. According to the documentation, the synthax should be QSQlQueryModel.setQuery(query, db=QSqlDatabase).
    That´s what I believe I do, but I get the error:
    TypeError: descriptor 'setQuery' for 'PySide6.QtSql.QSqlQueryModel' objects doesn't apply to a 'str' object

    Here´s the relevant code. There´s a lot of more code but it has nothing to do with the setQuery.

    from PySide6.QtWidgets import QApplication, QMainWindow, QTableWidgetItem
    from PySide6 import QtSql, QtCore, QtGui, QtWidgets
    
    class Frm_Indications(QMainWindow, Ui_frmIndications):
        
        def __init__(self):
            super().__init__()
            self.setupUi(self)
            self.mod_Indication = QtSql.QSqlQueryModel
    
        def Search(self):
            self.mod_Indication.setQuery("SELECT * FROM qryIndication ", db = self.db_assess)
    
    

    Hope anyone can help me what I do wrong... Many thanks!

    Seamus

    jsulmJ 2 Replies Last reply
    0
    • S Offline
      S Offline
      SeamusQDraide
      wrote last edited by
      #5

      Solved: Missing parenthesis in
      self.mod_Indication = QtSql.QSqlQueryModel
      correct:
      self.mod_Indication = QtSql.QSqlQueryModel()

      1 Reply Last reply
      1
      • S SeamusQDraide

        Hi everyone!

        I have a problem handing over the query to the setQuery() function. According to the documentation, the synthax should be QSQlQueryModel.setQuery(query, db=QSqlDatabase).
        That´s what I believe I do, but I get the error:
        TypeError: descriptor 'setQuery' for 'PySide6.QtSql.QSqlQueryModel' objects doesn't apply to a 'str' object

        Here´s the relevant code. There´s a lot of more code but it has nothing to do with the setQuery.

        from PySide6.QtWidgets import QApplication, QMainWindow, QTableWidgetItem
        from PySide6 import QtSql, QtCore, QtGui, QtWidgets
        
        class Frm_Indications(QMainWindow, Ui_frmIndications):
            
            def __init__(self):
                super().__init__()
                self.setupUi(self)
                self.mod_Indication = QtSql.QSqlQueryModel
        
            def Search(self):
                self.mod_Indication.setQuery("SELECT * FROM qryIndication ", db = self.db_assess)
        
        

        Hope anyone can help me what I do wrong... Many thanks!

        Seamus

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote last edited by
        #2
        This post is deleted!
        1 Reply Last reply
        0
        • S SeamusQDraide

          Hi everyone!

          I have a problem handing over the query to the setQuery() function. According to the documentation, the synthax should be QSQlQueryModel.setQuery(query, db=QSqlDatabase).
          That´s what I believe I do, but I get the error:
          TypeError: descriptor 'setQuery' for 'PySide6.QtSql.QSqlQueryModel' objects doesn't apply to a 'str' object

          Here´s the relevant code. There´s a lot of more code but it has nothing to do with the setQuery.

          from PySide6.QtWidgets import QApplication, QMainWindow, QTableWidgetItem
          from PySide6 import QtSql, QtCore, QtGui, QtWidgets
          
          class Frm_Indications(QMainWindow, Ui_frmIndications):
              
              def __init__(self):
                  super().__init__()
                  self.setupUi(self)
                  self.mod_Indication = QtSql.QSqlQueryModel
          
              def Search(self):
                  self.mod_Indication.setQuery("SELECT * FROM qryIndication ", db = self.db_assess)
          
          

          Hope anyone can help me what I do wrong... Many thanks!

          Seamus

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote last edited by
          #3

          @SeamusQDraide said in QSqlQueryModel.setQuery() won´t accept strg:

          self.mod_Indication.setQuery("SELECT * FROM qryIndication ", db = self.db_assess)

          What type is self.db_assess ?

          S 1 Reply Last reply
          0
          • jsulmJ jsulm

            @SeamusQDraide said in QSqlQueryModel.setQuery() won´t accept strg:

            self.mod_Indication.setQuery("SELECT * FROM qryIndication ", db = self.db_assess)

            What type is self.db_assess ?

            S Offline
            S Offline
            SeamusQDraide
            wrote last edited by SeamusQDraide
            #4

            @jsulm

            It´s an SQlite db (self.database_assess is a str containing the path to the db):

                    self.db_assess = QtSql.QSqlDatabase.addDatabase("QSQLITE", self.database_assess)
                    self.db_assess.setDatabaseName(programmpfad + self.database_assess)
                    self.db_assess.open()
            
            1 Reply Last reply
            0
            • S Offline
              S Offline
              SeamusQDraide
              wrote last edited by
              #5

              Solved: Missing parenthesis in
              self.mod_Indication = QtSql.QSqlQueryModel
              correct:
              self.mod_Indication = QtSql.QSqlQueryModel()

              1 Reply Last reply
              1
              • S SeamusQDraide has marked this topic as solved

              • Login

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