[PyKDE] Signals and Slots not working
Rick van Hattem
Rick.van.Hattem at fawo.nl
Sat Dec 30 05:14:36 GMT 2006
On Saturday 30 December 2006 02:45, paulino1 at sapo.pt wrote:
> 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
>
> _______________________________________________
> PyKDE mailing list PyKDE at mats.imk.fraunhofer.de
> http://mats.imk.fraunhofer.de/mailman/listinfo/pykde
My apologies, I didn't copy it correctly.
Here's the correct one. I've changed the setValue() to setValue(int) and
valueChanged() to valueChanged(int).
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(int)'), slider,
SLOT('setValue(int)'))
QObject.connect( slider, SIGNAL('valueChanged(int)'), spinbox,
SLOT('setValue(int)'))
spinbox.setValue(35)
layout = QHBoxLayout()
layout.addWidget(spinbox)
layout.addWidget(slider)
window.setLayout(layout)
window.show()
app.exec_()
--
Rick van Hattem Rick.van.Hattem(at)Fawo.nl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20061230/cc8da386/attachment.bin
More information about the PyQt
mailing list