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. QSortFilterProxyModel(AttributeError: 'X' object has no attribute 'Y')
Forum Updated to NodeBB v4.3 + New Features

QSortFilterProxyModel(AttributeError: 'X' object has no attribute 'Y')

Scheduled Pinned Locked Moved Solved Qt for Python
5 Posts 2 Posters 1.8k 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.
  • A Offline
    A Offline
    adrian88888888
    wrote on last edited by adrian88888888
    #1

    Hi, my objective was to make a treeview with data on it and to be able to sort the data:

    alt text

    So far I managed to:
    1-connect to a DataBase
    2-make a model using the database
    3-dropping the model inside a warper so it can be sorted (QSortFilterProxyModel)
    4-then I filtered the model using a regular expression....and here is the problem, i get an error:

    AttributeError: 'PySide2.QtCore.QSortFilterProxyModel' object has no attribute 'setFilterRegExpression'
    

    This is the line of code that gives the error:

    self.ui.model_sorted.setFilterRegExpression(QRegularExpression("(red|blue)"))
    

    I tried stuff but so far i didn't get the solution, i think a self is missing somewhere or that it has something to do with private and public methods/classes, but i'm not sure

    .---------------------------------------------------------------

    the code(i dont think its necessary to read, but just in case):

    def Starting_DataBase(self):
            #CONNECTING TO THE DATABASE:
            self.ui.db = QSqlDatabase.addDatabase('QSQLITE')
            self.ui.db.setDatabaseName('The directory\DataBase.db')
            self.ui.db.open()
            #MAKING THE MODEL USING THE DATABASE:
            self.ui.model = QSqlTableModel()
            self.ui.model.setTable('Table_Name')
            self.ui.model.setEditStrategy(QSqlTableModel.OnManualSubmit)
            self.ui.model.select()
            #PUTTING THE MODEL INSIDE A WARPER THAT CAN SORT AND FILTER IT:
            self.ui.model_sorted = QSortFilterProxyModel()
            self.ui.model_sorted.setSourceModel(self.ui.model)
            self.ui.model_sorted.setFilterKeyColumn(1) #ESTE NO SE QUE HACE
            self.ui.model_sorted.setFilterRegExpression(QRegularExpression("(red|blue)"))
            #MAKING THE RELATIONSHIP BETWEEN THE TABLEVIEW AND THE MODEL_SORTED:
            self.ui.demosTree.setModel(self.ui.model_sorted)
    
    JonBJ 1 Reply Last reply
    0
    • A adrian88888888

      Hi, my objective was to make a treeview with data on it and to be able to sort the data:

      alt text

      So far I managed to:
      1-connect to a DataBase
      2-make a model using the database
      3-dropping the model inside a warper so it can be sorted (QSortFilterProxyModel)
      4-then I filtered the model using a regular expression....and here is the problem, i get an error:

      AttributeError: 'PySide2.QtCore.QSortFilterProxyModel' object has no attribute 'setFilterRegExpression'
      

      This is the line of code that gives the error:

      self.ui.model_sorted.setFilterRegExpression(QRegularExpression("(red|blue)"))
      

      I tried stuff but so far i didn't get the solution, i think a self is missing somewhere or that it has something to do with private and public methods/classes, but i'm not sure

      .---------------------------------------------------------------

      the code(i dont think its necessary to read, but just in case):

      def Starting_DataBase(self):
              #CONNECTING TO THE DATABASE:
              self.ui.db = QSqlDatabase.addDatabase('QSQLITE')
              self.ui.db.setDatabaseName('The directory\DataBase.db')
              self.ui.db.open()
              #MAKING THE MODEL USING THE DATABASE:
              self.ui.model = QSqlTableModel()
              self.ui.model.setTable('Table_Name')
              self.ui.model.setEditStrategy(QSqlTableModel.OnManualSubmit)
              self.ui.model.select()
              #PUTTING THE MODEL INSIDE A WARPER THAT CAN SORT AND FILTER IT:
              self.ui.model_sorted = QSortFilterProxyModel()
              self.ui.model_sorted.setSourceModel(self.ui.model)
              self.ui.model_sorted.setFilterKeyColumn(1) #ESTE NO SE QUE HACE
              self.ui.model_sorted.setFilterRegExpression(QRegularExpression("(red|blue)"))
              #MAKING THE RELATIONSHIP BETWEEN THE TABLEVIEW AND THE MODEL_SORTED:
              self.ui.demosTree.setModel(self.ui.model_sorted)
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @adrian88888888 said in QSortFilterProxyModel(AttributeError: 'X' object has no attribute 'Y'):

      setFilterRegExpression

      As per docs, it's setFilterRegularExpression().

      1 Reply Last reply
      1
      • A Offline
        A Offline
        adrian88888888
        wrote on last edited by
        #3

        How did you noticed?, those things escape from me, thanks!!!!!!

        JonBJ 1 Reply Last reply
        0
        • A adrian88888888

          How did you noticed?, those things escape from me, thanks!!!!!!

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

          @adrian88888888
          I'm afraid that getting the exact right spelling of functions is a requirement for writing code :)

          Now you know that in Python a message like

          AttributeError: 'PySide2.QtCore.QSortFilterProxyModel' object has no attribute 'setFilterRegExpression'
          

          is what you get for a method of a class does not exist. It will refer to a method (and, I think, a variable) as an "attribute" of the class, because that's how Python works.

          A 1 Reply Last reply
          0
          • JonBJ JonB

            @adrian88888888
            I'm afraid that getting the exact right spelling of functions is a requirement for writing code :)

            Now you know that in Python a message like

            AttributeError: 'PySide2.QtCore.QSortFilterProxyModel' object has no attribute 'setFilterRegExpression'
            

            is what you get for a method of a class does not exist. It will refer to a method (and, I think, a variable) as an "attribute" of the class, because that's how Python works.

            A Offline
            A Offline
            adrian88888888
            wrote on last edited by
            #5

            @JonB oh, i see, I have a new mental note now, newbie problems

            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