[Interest] A problem about signals/slots in Qt 5

程梁 devbean at outlook.com
Tue Sep 4 07:31:10 CEST 2012


I see. I thought the new syntax could replace the old one. It seems that I was wrong. (BTW, it is gcc to compile. My words about qmake compile was wrong.)

Thank you for your quick reply!

Cheng Liang
Nanjing, China
http://www.devbean.info

From: thiago.macieira at intel.com
To: interest at qt-project.org
Date: Tue, 4 Sep 2012 07:22:55 +0200
Subject: Re: [Interest] A problem about signals/slots in Qt 5

On terça-feira, 4 de setembro de 2012 05.14.17, 程梁 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?
 
It's not a simple syntax:
 
> 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. It is a Makefile generator. You're using GCC to 
compile.
 
>     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?
 
Option 1: use the Qt 4 syntax. It's still valid.
 
Option 2:
    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

_______________________________________________
Interest mailing list
Interest at qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120904/f08846d0/attachment.html>


More information about the Interest mailing list