Qt new style signals/slots

Willem Ferguson willemferguson at zoology.up.ac.za
Sat Jan 18 03:48:02 PST 2020


Following excellent review of a recent PR, I was asked to update the 
conventional string-based Qt connections to the new-style Qt 
connections. (https://wiki.qt.io/New_Signal_Slot_Syntax) The old style is:

connect(
     sender, SIGNAL( valueChanged( QString, QString ) ),
     receiver, SLOT( updateValue( QString ) )
);

My old-style connection is:

connect(ui.timeDiffEdit, SIGNAL(timeChanged(const QTime)), this, 
SLOT(timeDiffEditChanged()));

For the new style the specification in the Qt documentation is:

connect(
     sender, &Sender::valueChanged,
     receiver, &Receiver::updateValue
);

My formulation, reflecting my strong deficiencies in Qt coding but 
following the above, for the new connection is:

connect(this, 
ui.timeDiffEdit->timeChanged(ui.timeDiffEdit->time()),this, 
this->timeDiffEditChanged());

The second parameter needs to be a pointer, for which I used 
ui.timeDiffEdit. The timeChanged() signal needs a QTime value, so I 
provided that with ui.timeDeffEdit->time(), the actual amount of time by 
which the timeDiffEdit has been changed.

The last parameter also needs an address, provided by 
this->timeDiffEditChanged() is the response to the signal 
fromtimeDiffEdit->timeChanged(). It is a void function and the source of 
build problems. The compiler generates an error:

/home/willem/src/subsurface/desktop-widgets/importgps.cpp:30:104: error: 
invalid use of void expression
connect(this, ui.timeDiffEdit->timeChanged(ui.timeDiffEdit->time()), 
this, this->timeDiffEditChanged());
^

Obviously, accessing the pointer this->timeDiffEditChanged() should not 
return a void value. I have no idea of how to respond to this error. Any 
suggestions are very welcome. For completeness I attach the code for the 
full object to this email.

Kind regards,

willem




-- 
This message and attachments are subject to a disclaimer.

Please refer to 
http://upnet.up.ac.za/services/it/documentation/docs/004167.pdf 
<http://upnet.up.ac.za/services/it/documentation/docs/004167.pdf> for
full 
details.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20200118/4e149264/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: importgps.cpp
Type: text/x-c++src
Size: 12544 bytes
Desc: not available
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20200118/4e149264/attachment.cpp>


More information about the subsurface mailing list