Y
Y
Yu Yu2015-03-05 12:27:46
Qt
Yu Yu, 2015-03-05 12:27:46

Is it possible to override base class signals?

There is a class with a signal that provides an interface

class IA
{
signal: void sigA();
}
есть класс A реализация
class A
{
emit sigA();
}

somewhere in the main program:
IA* iterface = new A();
// тут подключаем сигнал
connect (interface, SIGNAL(sigA), this, SLOT(anySlot()));

But the slot doesn't work.
What to do with the signal so that it works in the implementation of the child?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
V
Vitaly, 2015-03-05
@vt4a2h

Everything is quite simple (you can do the same with slots):

class IFoo
{
public:
    virtual void signal1() = 0;
    virtual void signal2() = 0;
}

class Bar : public QObject, public IFoo
{
    // ...
signals:
    void signal1();
    void signal2();
}

There is no virtual inheritance for QObject in Qt. And the bodies of purely virtual methods will be generated in moc_* files.

A
Armenian Radio, 2015-03-05
@gbg

emit sigA() needs to be done. Or doesn't work?

J
jackroll, 2015-03-05
@jackroll

If I understand you correctly:
You need to create a slot that will call the signal signA();
For example:

//Где то внутри какого-то класса
bublik slots:
  void callSignA()
  { emit signA();  }
signal:
  signA();

//Где-то в каком-то файле.cpp
QObject::connect(куПушБатон, SIGNAL(clicked), this, SLOT(signA()));
QObject::connect(this, SIGNAL(signA()), someWgt, SLOT(someSlot()));

D
DancingOnWater, 2015-03-05
@DancingOnWater

General remark based on experience. On the plus side, the interface in the strict sense is rarely used; an abstract class is often needed.
To use signals in Qt, there is only one way described in the doc - to inherit from QObject

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question