-2

I wrote a simple application in Python and PySide. When I run it, SIGNALs are not working. The application starts without errors.

from PySide.QtCore import *
from PySide.QtGui import *
import sys

class Form(QDialog):

    def __init__(self, parent=None):
        super(Form, self).__init__(parent)

        dial = QDial()
        dial.setNotchesVisible(True)

        spinbox = QSpinBox()

        layout = QHBoxLayout()
        layout.addWidget(dial)
        layout.addWidget(spinbox)
        self.setLayout(layout)

        self.connect(dial, SIGNAL("valueChaged(int)"), spinbox.setValue)
        self.connect(spinbox, SIGNAL("valueChaged(int)"), dial.setValue)

        self.setWindowTitle("Signals and Slots")
    # END def __init__
# END class Form

def main():
    app = QApplication(sys.argv)
    form = Form()
    form.show()
    app.exec_()
# END def main

if __name__ == '__main__':
    main()
# END if

I am using:

Pyside 1.2.2; Python 2.7.6; OS Centos; Windows 7

I am running the application with:

Sublime Text 3 and Eclipse Luna;

How can I make SIGNALs working?

Romulus
  • 1,150
  • 3
  • 16
  • 26

1 Answers1

1

Your signal name is incorrect;

Incorrect :

valueChaged (int)

Correct :

valueChanged (int)

Test it, work fine;

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

class QFormDialog (QDialog):
    def __init__(self, parent = None):
        super(QFormDialog, self).__init__(parent)
        self.myQial = QDial()
        self.myQSpinbox = QSpinBox()
        self.myQHBoxLayout = QHBoxLayout()
        self.myQial.setNotchesVisible(True)
        self.myQHBoxLayout.addWidget(self.myQial)
        self.myQHBoxLayout.addWidget(self.myQSpinbox)
        self.setLayout(self.myQHBoxLayout)
        self.connect(self.myQial,     SIGNAL('valueChanged(int)'), self.myQSpinbox.setValue)
        self.connect(self.myQSpinbox, SIGNAL('valueChanged(int)'), self.myQial.setValue)
        self.setWindowTitle('Signals and Slots')

if __name__ == '__main__':
    myQApplication = QApplication(sys.argv)
    myQFormDialog = QFormDialog()
    myQFormDialog.show()
    myQApplication.exec_()

Note : PyQt4 & PySide is same way to implemented.

Bandhit Suksiri
  • 3,390
  • 1
  • 18
  • 20