PyQT Signals Problem [Solved]

Questions about programming languages and debugging
Post Reply
User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

PyQT Signals Problem [Solved]

Post by maboroshi »

Trying to build a simple GUI in PyQT

I build a QLineEdit Widget and a QButton Widget. I want to reference the entered text in QLineEdit from a function my code as follows

Code: Select all

class MainWindow(QtGui.QWidget):
    def __init__(self, parent=None):
......

     colorEdit = QtGui.QLineEdit()
......
     self.connect(colorEdit, QtCore.SIGNAL("returnPressed()"), self.newMovie)
......
    def newMovie(self):
          # This is where it goes wrong with attribute errors
          mycolor = self.colorEdit.text()
......

But I keep getting an Attribute error not sure what I am doing wrong suggestions?
AttributeError: 'MainWindow' object has no attribute 'colorEdit'
Last edited by maboroshi on 27 Nov 2009, 12:23, edited 1 time in total.

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Now, I'm not very into Python, but I do use QT.

Not really sure this will help, but it's a damage from using too much C++

Try replacing

Code: Select all

mycolor = self.colorEdit.text()
with

Code: Select all

mycolor = colorEdit.text()
Since it would seem as if it looks for the colorEdit attribute in the MainWindow class from the QT library, and not yours.

Keep in mind that I don't know how the Python syntax work, but it's on my list of things I want to do before I die ^^
"The best place to hide a tree, is in a forest"

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Hey Cats

Post by maboroshi »

Hey Cats thanks for the fast reply but I had tried that also and still get an attribute error

perhaps maybe when creating my variable if I type self.colorEdit = QtGui.QLineEdit

maybe that might fix it, worth a try *confused

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

Did it fix it? =)
"The best place to hide a tree, is in a forest"

User avatar
leetnigga
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 447
Joined: 28 Jul 2009, 16:00
14

Post by leetnigga »

Is the definition of colorEdit in __init__? You'll want to use self there too.

Code: Select all

class MainWindow(QtGui.QWidget):
    def __init__(self, parent=None):
        self.colorEdit = QtGui.QLineEdit()

User avatar
maboroshi
Dr. Mab
Dr. Mab
Posts: 1624
Joined: 28 Aug 2005, 16:00
18

Yep

Post by maboroshi »

Yep that solved it.

Thanks for the help leet and cats *cheers

Post Reply