[Interest] Signal and Slot mechansim in Qt4.8.x

2014-08-08 Thread Ramakanthreddy Kesireddy
Hi,

I got a usecase where I had implemented in Qt4.8.x app on the assumption that 
slots execute one after another in the order they are connected.

HMI response is slow when continuous data is pumped into my application from 
other device.
Though we maintain separate threads(threads implementation being derived from 
Qthread) for reading from the ports and writing onto temporary buffers, HMI is 
still slow to respond while view switching.

If multiple signals are emitted once, I would like to know if framework would 
take care of slots execution in parallel or in sequential order.

Thanks and Regards,
Ramakanth



DISCLAIMER:
This email (including any attachments) is intended for the sole use of the 
intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE 
COMPANY INFORMATION. Any review or reliance by others or copying or 
distribution or forwarding of any or all of the contents in this message is 
STRICTLY PROHIBITED. If you are not the intended recipient, please contact the 
sender by email and delete all copies; your cooperation in this regard is 
appreciated.



Disclaimer:  This message and the information contained herein is proprietary 
and confidential and subject to the Tech Mahindra policy statement, you may 
review the policy at http://www.techmahindra.com/Disclaimer.html externally 
http://tim.techmahindra.com/tim/disclaimer.html internally within TechMahindra.


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


Re: [Interest] Signal and Slot mechansim in Qt4.8.x

2014-08-08 Thread Bo Thorsen
Hi,

The order of the slots execution is undefined. You can not rely on it.

Bo.

Den 08-08-2014 10:39, Ramakanthreddy Kesireddy skrev:
 Hi,

 I got a usecase where I had implemented in Qt4.8.x app on the assumption
 that slots execute one after another in the order they are connected.

 HMI response is slow when continuous data is pumped into my application
 from other device.

 Though we maintain separate threads(threads implementation being derived
 from Qthread) for reading from the ports and writing onto temporary
 buffers, HMI is still slow to respond while view switching.

 If multiple signals are emitted once, I would like to know if framework
 would take care of slots execution in parallel or in sequential order.


-- 
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Signal and Slot mechansim in Qt4.8.x

2014-08-08 Thread Giuseppe D'Angelo

Il 08/08/2014 10:51, Bo Thorsen ha scritto:

The order of the slots execution is undefined. You can not rely on it.


Generally speaking it *is* defined: slot activation follows the order of 
the connect() statements (*).


In this specific case, there are multiple threads in the game, and the 
question doesn't elaborate enough on what's the actual structure of the 
connections (which threads emit which signals? what are those signals 
connected to? which connection types are sued?) to be able to know 
what's going on.


(*) It has been finalized, by documenting it, around Qt 4.6. I guess 
simply too many people were relying on that behaviour (which was 
implemented, just not documented) to think to modify it at any time.


HTH,
--
Join us Oct 6-8 at BCC Berlin for Qt Developer Days 2014!
Giuseppe D'Angelo | giuseppe.dang...@kdab.com | Software Engineer
KDAB (UK) Ltd., a KDAB Group company
Tel. UK +44-1738-450410, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions



smime.p7s
Description: Firma crittografica S/MIME
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Signal and Slot mechansim in Qt4.8.x

2014-08-08 Thread Bo Thorsen
Den 08-08-2014 12:15, Giuseppe D'Angelo skrev:
 Il 08/08/2014 10:51, Bo Thorsen ha scritto:
 The order of the slots execution is undefined. You can not rely on it.

 Generally speaking it *is* defined: slot activation follows the order of
 the connect() statements (*).

Yes.

 In this specific case, there are multiple threads in the game, and the
 question doesn't elaborate enough on what's the actual structure of the
 connections (which threads emit which signals? what are those signals
 connected to? which connection types are sued?) to be able to know
 what's going on.

It's the threads that kill this. He said that multiple threads are 
emitting at the same time (I'm assuming this means multiple cores on the 
target machine). I think it would be very dangerous to assume anything 
on the ordering of this. If he needs a strict order of this, he should 
implement a producer-consumer system for the messages instead.

Bo.

-- 
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Signal and Slot mechansim in Qt4.8.x

2014-08-08 Thread Till Oliver Knoll
Am 08.08.2014 um 10:39 schrieb Ramakanthreddy Kesireddy 
ramakanthreddy.kesire...@techmahindra.com:

 ...
  
 If multiple signals are emitted once, I would like to know if framework would 
 take care of slots execution in parallel or in sequential order.

For direct connections slots are always executed in the same thread from 
where the signal originated.

As Bo already pointed out if you have several slots - directly - connected to a 
given signal, then they are sequentially processed - in /any/ 
(undefined/undocumented) order!

If on the other hand those slots are indirectly connected (aka Queued 
Connection) then the slots are processed in their respective threads.

So if you have N threads and each is connecting a distinct slot to a given 
signal with a queued connection (implying that each thread is running its own 
event queue), when this signal fires then the N slots execute in parallel (as 
far as the thread scheduler allows).

Read more in the Qt docs, Signals and Slots Across Threads.

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


Re: [Interest] Signal and Slot mechansim in Qt4.8.x

2014-08-08 Thread Till Oliver Knoll
Am 08.08.2014 um 12:15 schrieb Giuseppe D'Angelo giuseppe.dang...@kdab.com:

 Il 08/08/2014 10:51, Bo Thorsen ha scritto:
 The order of the slots execution is undefined. You can not rely on it.
 
 Generally speaking it *is* defined: slot activation follows the order of the 
 connect() statements (*).

But, but...!


 
 ...
 
 (*) It has been finalized, by documenting it, around Qt 4.6. I guess simply 
 too many people were relying on that behaviour 

I was just about to complain ;) Didn't realise that this behaviour has been 
made official now :)

It might be okay if you have a /single/ class connecting to a given signal in 
a well-defined order. But as soon as slots of multiple classes are to be 
connected to a given signal in a well-defined order such a design would 
probably be doomed to fail rather sooner than later, IMHO.

So I'm a bit surprised that people started to rely on the connection order (I 
remember faintly that some Qt docs even stated clearly that the order was 
undefined).

But then again, nothing should surprise me anymore in software engineering 
(just frighten) ;)

Cheers,
  Oliver
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest


Re: [Interest] Signal and Slot mechansim in Qt4.8.x

2014-08-08 Thread Bo Thorsen
Den 08-08-2014 14:03, Till Oliver Knoll skrev:
 Am 08.08.2014 um 12:15 schrieb Giuseppe D'Angelo giuseppe.dang...@kdab.com:

 Il 08/08/2014 10:51, Bo Thorsen ha scritto:
 The order of the slots execution is undefined. You can not rely on it.

 Generally speaking it *is* defined: slot activation follows the order of the 
 connect() statements (*).

 But, but...!



 ...

 (*) It has been finalized, by documenting it, around Qt 4.6. I guess simply 
 too many people were relying on that behaviour

 I was just about to complain ;) Didn't realise that this behaviour
 has been made official now :)

Yep, it says so on the internet 
(http://qt-project.org/doc/qt-5/signalsandslots.html) so it must be true :)

 It might be okay if you have a /single/ class connecting to a given
 signal in a well-defined order. But as soon as slots of multiple
 classes are to be connected to a given signal in a well-defined
 order such a design would probably be doomed to fail rather sooner
 than later, IMHO.

As long as your application is single threaded, then the order is 
perfectly well defined. If you think of connections as implementations 
of the visitor pattern with one visitor object in a list of signals, 
then it's not hard to do this. Emitting a signal and the connected slot 
calls are exactly the same as calling any C++ function, so the order is 
easy.

The most surprising thing to me is that it took until 4.6 before this 
was documented, since there doesn't seem to be any good reason not to 
implement connects as a list and call these one after the other.

Bo.

-- 
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu
___
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest