[PyKDE] Signals and Slots not working

paulino1 at sapo.pt paulino1 at sapo.pt
Sat Dec 30 01:45:50 GMT 2006


These connections statements are not working

QObject.connect( spinbox, SIGNAL('valueChanged()'), slider, SLOT('setValue()'))
QObject.connect( slider, SIGNAL('valueChanged()'), spinbox, SLOT('setValue()'))



I'm reading "C++ Gui Programming with Qt4" and trying out the exemples given
there in python.

I translated this code:

 1 #include <QApplication>  2 #include <QHBoxLayout>
 3 #include <QSlider>
 4 #include <QSpinBox>
 5 int main(int argc, char *argv[])
 6 {
 7     QApplication app(argc, argv);
 8     QWidget *window = new QWidget;
 9     window->setWindowTitle("Enter Your Age");
10     QSpinBox *spinBox = new QSpinBox;
11     QSlider *slider = new QSlider(Qt::Horizontal);
12     spinBox->setRange(0, 130);
13     slider->setRange(0, 130);
14     QObject::connect(spinBox, SIGNAL(valueChanged(int)),
15                      slider, SLOT(setValue(int)));
16     QObject::connect(slider, SIGNAL(valueChanged(int)),
17                      spinBox, SLOT(setValue(int)));
18     spinBox->setValue(35);
19     QHBoxLayout *layout = new QHBoxLayout;
20     layout->addWidget(spinBox);
21     layout->addWidget(slider);
22     window->setLayout(layout);
23     window->show();
24     return app.exec();
25 }


into this python code

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

app = QApplication( argv)

window = QWidget()
window.setWindowTitle("Enter Your Age")

spinbox = QSpinBox()
spinbox.setRange(0, 130)

slider = QSlider( Qt.Horizontal )
slider.setRange(0, 130)

QObject.connect( spinbox, SIGNAL('valueChanged()'), slider, SLOT('setValue()'))
QObject.connect( slider, SIGNAL('valueChanged()'), spinbox, SLOT('setValue()'))
spinbox.setValue(35)

layout = QHBoxLayout()
layout.addWidget(spinbox)
layout.addWidget(slider)

window.setLayout(layout)
window.show()
app.exec_()


The layout is OK but the connections have something wrong that I can't figure.

Paulino
___________________________________________________________________

O SAPO já está livre de vírus com a Panda Software, fique você também!
Clique em: http://antivirus.sapo.pt




More information about the PyQt mailing list