1

I have this small media app that holds two buttons that should start and stop music. but there is something wrong to my logic... please take a look:

class AppWindow(QtGui.QWidget):

    def mediastart():
        os.system("...")

    def mediastop():
        os.system("...")

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

        self.setGeometry(300, 300, 800, 480)
        self.setWindowTitle("EasySteerQT")

        start = QtGui.QPushButton("Start", self)
        start.setGeometry(50, 50, 60, 35)

        stop = QtGui.QPushButton("Stop", self)
        stop.setGeometry(100, 50, 60, 35)

        quit = QtGui.QPushButton('Close', self)
        quit.setGeometry(10, 10, 60, 35)

        self.connect(quit, QtCore.SIGNAL("clicked()"),
            QtGui.qApp, QtCore.SLOT("quit()"))

        self.connect(start, QtCore.SIGNAL("clicked()"),
            QtGui.qApp, QtCore.SLOT("mediastart()"))

        self.connect(start, QtCore.SIGNAL("clicked()"),
            self, QtCore.SLOT("mediastop()"))

in what way is the propper way to connect a action to a function in this class?

1 Answer 1

4

Use self.mediastop. QtCore.SLOT('mediastop()') refers to a (in this case non-existent) slot defined in C++. Not that that's not really necessary anyway, you can use WidgetClass.slotName - it just saves you a conversion.

And while we're at it, you should propably switch from old-style signals/slots to new-style signals/slots. E.g. self.clicked.connect(self.mediastop).

Sign up to request clarification or add additional context in comments.

1 Comment

ty ty, i like the new style :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.