[Qt-interest] Data exchange in threads

Николай Шатохин n.shatokhin at gmail.com
Tue Apr 26 16:00:30 CEST 2011


1. How to modify signal/slot?

2. What is the dedicated objects?

3. So thread send signal to all threads, and this threads send signal
back? Is it fast?

2011/4/26 BRM <bm_witness at yahoo.com>:
> There are numerous ways, which is best depends on what you are doing.
>
> 1. Use a modified signal/slot:
> - include a 'client ID' in the signal
> - the network connection is wrapped such that it knows its 'client ID'
> - only forwards data to the client if the client ID matches.
>
> 2. Use dedicated objects with signals/slots
> - each object interfaces for the entire session of the client, interfacing to
> the internal parts as necessary, not necessarily with signals/slots. This will
> require locks/etc.
> - each object has a normal signal/slot interface to the client it is servicing.
>
> 3. QObject->sender()
> - when you receive a call to a certain slot, get the signal sender, generate the
> result and then send it back only to the sender.
> - this requires that the sender() be able to be qobject_cast<>() to a known
> QObject derived class with a known interface (slot) to send the data back on.
>
> I have used #3 for certain tasks. #2 may be more to your fitting, but it
> certainly the harder method in most cases since you have to figure out the
> locks, etc and you can't take full advantage of signals/slots.
>
> So as I said - it's a matter of your system design and what works best. For me,
> #3 was a simple enough solution for something where I wanted one client to have
> total control of a multi-message process but it's not necessarily correct for
> you - and it certainly breaks signal-slot OO practices (since you're not really
> suppose to care who calls a slot).
>
> $0.02
>
> Ben
>
>
>
> ----- Original Message ----
>> From: Николай Шатохин <n.shatokhin at gmail.com>
>> To: "qt-interest at qt.nokia.com" <Qt-interest at qt.nokia.com>
>> Sent: Tue, April 26, 2011 9:02:48 AM
>> Subject: [Qt-interest] Data exchange in threads
>>
>> Hello.
>>
>> I have one server on qt4, one client on qt4 and entry point on  php.
>>
>> Client can send data to php by json and send data to server  (this
>> action dynamically create new thread on server). Php can send data  on
>> server too (it's no difference for server who send data). So we  have
>> two thread created dynamically - one for client, one for entry  (this
>> threads on server can be thousands or millions). So, how can  entry's
>> thread send data only for this client's thread? If I'll  you
>> signals/slot, all threads send data to all threads and all  threads
>> must do checking (it's signal for me or not?). It's very slow. So,  can
>> I use some quick  method?
>> _______________________________________________
>> Qt-interest  mailing list
>> Qt-interest at qt.nokia.com
>> http://lists.qt.nokia.com/mailman/listinfo/qt-interest
>>
>



More information about the Qt-interest-old mailing list