On terça-feira, 4 de setembro de 2012 04.59.19, 程梁 wrote:
> Hi, there! I try to connect signals and slot in Qt 5 using new syntax. But I
> have a question: how to connect overloaded signals to special slots?

You need to load it to a variable first to resolve the overload.

> For example, I have the following code:
>
>     QSpinBox *spinBox = new QSpinBox(&window);
>     QSlider *slider = new QSlider(Qt::Horizontal, &window);
>
>     QObject::connect(slider, &QSlider::valueChanged, spinBox,
> &QSpinBox::setValue);
 QObject::connect(spinBox, &QSpinBox::valueChanged,
> slider, &QSlider::setValue);
> valueChanged() in QSpinBox is an overloaded signal. When I use qmake 2.01a
> to compile it, the error shows:

Note: qmake doesn't compile. GCC compiles.

>     no matching function for call to 'QObject::connect(QSpinBox*&,
> <unresolved overloaded function type>, QSlider*&, void
> (QAbstractSlider::*)(int))'

> How could I solve this?
>
> In Qt 4 I could specialize the signal using SIGNAL(valueChanged(int)), how
> could I do in Qt 5?

    void (QSpinBox:: *signal)(int) = &QSpinBox::valueChanged;
    QObject::connect(spinBox, signal, slider, &QSlider::setValue);

--
Thiago Macieira - thiago.macieira (AT) intel.com
  Software Architect - Intel Open Source Technology Center
     Intel Sweden AB - Registration Number: 556189-6027
     Knarrarnäsgatan 15, 164 40 Kista, Stockholm, Sweden

Attachment: signature.asc
Description: This is a digitally signed message part.

_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to