vandelay
vandelay

Reputation: 2065

AttributeError: 'Window' object has no attribute 'q'

I'm trying to append a simple string to a list in and object. But I'm guessing the self keyword is interfereing with the pyqt window?

How can I work around this?

class Window(qt.QMainWindow):
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)
        self.CreateWidgets()       
        self.q = Qfetch.DataFetch()

    def CreateWidgets(self):
        toPortfolio = "str"
        self.q.Portfolio.append(toPortfolio) #<---- This cause the error

q class

class DataFetch():
    def __init__(self):
        self.Portfolio = []

Upvotes: 0

Views: 2444

Answers (1)

Filip Hedman
Filip Hedman

Reputation: 417

You are trying to fetch the member q before it is initialized. Call Qfetch.DataFetch() before self.CreateWidgets().

This code for the constructor should work:

class Window(qt.QMainWindow):
    def __init__(self, parent=None):
        super(Window, self).__init__(parent)
        self.q = Qfetch.DataFetch()
        self.CreateWidgets()       

Upvotes: 5

Related Questions