Qt's signal / slot mechanism over the network

It is false that you can't create a QGenericArgument yourself. You're advised not to, but what you're trying to do is very implementation-dependent anyway. There isn't much to it: you provide a type name, and a pointer to the data of a given type. E.g.:

QGenericArgument one() {
  static const char type[] = "int";
  static const int data = "1";
  return QGenericArgument{type, (void*)&data);
}

See the Introspectable Visitor section of this answer for more example code.

How do I ensure that types always get the same typeId when they are registered using Q_DECLARE_METATYPE(..)?

You don't. You should be using type names, and each process should resolve these to typeids locally.

Unless you want to implement it yourself, use something ready made, like the MIT-licensed qt-remote-signals.


You really should consider using Qt Remote Object since they accomplish everything that you need and more (heartbeat, automatic re-connection upon disconnect, works with either QLocalSocket or QTcpSocket under the hood, etc) It the easiest to get signals across the network with minimal effort that I know of.

https://doc.qt.io/qt-5/qtremoteobjects-index.html

You just need to define .rep text file, which is like an IDL definition file

class MyRemoteObject {
{
    SIGNAL(foo(int value));
    SIGNAL(bar(float value));
    SLOT(somethingChanged(int newValue));
};

and then it takes that .rep file to generate code for the server side (known as 'source') and code for the client side (known as 'replica') using a built-in repc compiler that is called by qmake or cmake. Every signals called by the 'source' is automatically sent across every connected 'replicas', and slots called by 'replicas' are received by the 'source'

Tags:

C++

Qt