Answer the question
In order to leave comments, you need to log in
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
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
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 questionAsk a Question
731 491 924 answers to any question