R
R
Robotex2011-02-14 14:47:09
Nginx
Robotex, 2011-02-14 14:47:09

QT4: send a signal to a specific thread?

Suppose, for example, that there is a messenger - it has a server part and a client part. Each client connection is carried out in a separate thread (QThread). Each client has a unique identifier (for example, the owner's e-mail address).
How do I transfer a message from one client to another now: each thread subscribes to a signal from the server. When one client sends a message, the server emits a signal and all threads look at the identifier of their client - the thread with which it matches the addressee sends a message to the client. Everything is simple and works great, but I have suspicions that this is somewhat wrong. What if there are millions of customers? Maybe there is a smarter way?
PS Each thread also has a unique numeric identifier assigned automatically upon creation. You can write to the database the correspondence of this ID and the postal address. But then again - how to send a signal to a thread with a specific ID?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ighor July, 2022-02-01
@Robotex

You can use https://doc.qt.io/archives/qt-4.8/qmetaobject.html...
But you need to remember that if you send a signal to a non-existent (remote) object, there will be a segmentation fault

D
Deimus, 2011-02-26
@Deimus

I think you need to midify the signal and make it with an integer type argument. After that, when sending a signal, you will need to specify the identifier of the desired thread. The thread, in turn, will check if the value of the argument of the received signal matches its identifier - it will process it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question