1

I am trying to connect a push button signal to a callable I created, but for some reason this error keeps on popping up. I've checked to make sure QtCore is imported ... what else am I missing?

Sample code:

from PyQt4 import QtCore
from PyQt4 import QtGui
import sys

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

        #Create window
        self.setFixedSize(400,180)
        self.setWindowTitle("Choose the files to use")

        #Create all layouts to be used by window
        self.windowLayout = QtGui.QVBoxLayout()
        self.fileLayout1 = QtGui.QHBoxLayout()
        self.fileLayout2 = QtGui.QHBoxLayout()
        self.fileLayout3 = QtGui.QHBoxLayout()

        #Create the prompt for user to load in the q script to use
        self.qFileTF = QtGui.QLineEdit("Choose the q script file to use")
        self.qFileButton = QtGui.QPushButton("Open")
        self.qFileButton.setFixedSize(100,27)
        self.fileLayout1.addWidget(self.qFileTF)
        self.fileLayout1.addWidget(self.qFileButton)

                    #Connect all the signals and slots
        self.connect(self.qFileButton, SIGNAL("pressed()"), self.loadFile)

        def loadFile():
            fileName = []

            selFile = QtGui.QFileDailog.getOpenFileName(self)
            print selFile
Orchainu
  • 59
  • 3
  • 8

2 Answers2

7

SIGNAL is inside QtCore, so the line should be:

self.connect(self.qFileButton, QtCore.SIGNAL("pressed()"), self.loadFile)

but you really should use the new style connections:

self.qFileButton.pressed.connect(self.loadFile)

And, unless you meant to differentiate a click from press/release couple, you'd better use clicked signal:

self.qFileButton.clicked.connect(self.loadFile)
mmitchell
  • 621
  • 5
  • 22
Avaris
  • 35,883
  • 7
  • 81
  • 72
1

SIGNAL is defined inside QtCore, so you must use it within QtCore namespace if you've imported QtCore as a whole. So use:

QtCore.SIGNAL(...)

instead of:

SIGNAL(...)

Or you can import SIGNAL from QtCore explicitly:

from PyQt4.QtCore import SIGNAL
Rostyslav Dzinko
  • 39,424
  • 5
  • 49
  • 62