Here's an idea that could work in this case: redefine the newConnection
signal in your QTcpServer
subclass.
If you do that, objects that connected with an instance of your server won't receive QTcpServer
's "version" of the signal, only the one you emit directly from your sub-class.
Here's a proof of concept: class A
is the QTcpServer
, foo
is the signal you're trying to "hijack", bar
is just another (hypothetical) of QTcpServer
's signals you don't need to touch.
class A: public QObject
{
Q_OBJECT
public:
A() {};
virtual void doit() {
qDebug() << "A::doit";
emit foo(1);
emit bar(1);
}
signals:
void foo(int);
void bar(int);
};
Class B
is your subclass. Notice that it redefines signal foo
, but doesn't do anything to bar
.
class B: public A
{
Q_OBJECT
public:
B() {};
virtual void doit() {
qDebug() << "B::doit";
emit foo(2);
emit bar(2);
}
signals:
void foo(int);
};
Class C
is a potential client, connects the signals/slots from a B
instance exactly like it would for an A
instance.
class C: public QObject
{
Q_OBJECT
public:
C() {
B *b = new B;
connect(b, SIGNAL(foo(int)), this, SLOT(foo(int)));
connect(b, SIGNAL(bar(int)), this, SLOT(bar(int)));
/* 1 */
b->doit();
/* 2 */
b->A::doit(); // call parent class's function
};
public slots:
void foo(int i) {
qDebug() << "foo: " << i;
}
void bar(int i) {
qDebug() << "bar: " << i;
}
};
Here's the output from constructing a C
:
B::doit // this is /* 1 */
foo: 2
bar: 2
A::doit // this is /* 2 */
bar: 1
... and nothing else. A
's emit foo(1)
isn't connected to C
's foo
slot, it will never arrive to C
. A
's emit bar(1)
worked as expected, that signal is untouched.
With that setup, you can emit newConnection
when your class is ready, QTcpServer
's version of the signal will not be received by your user's objects.