PDA

View Full Version : Signal inside an abstract class



ayanda83
17th February 2017, 11:02
Hi there guys. I have this abstract class below.
class Page : public QObject
{
Q_OBJECT
public:
explicit Page(QObject *parent = 0);
virtual void start_downloading() = 0;
signals:
void done();
public slots:

}; As you can see that there is a signal Page::done() in the class. I have a bunch of concrete classes that inherit this class and the concrete classes will emit the signal Page::done() above. I have a separate class that works with the concrete classes and problem is connecting the above signal to any slot and I suppose its because the signal exists in an abstract class. Is there a way of connecting this signal.

Santosh Reddy
17th February 2017, 12:54
The concrete classes inheriting abstract Page class will also inherit the signals (and slots), so connecting to signal should be just as usual, should not be any different for Abstract class signal (or slot) / Concrete class signal (or slot).

d_stranz
17th February 2017, 19:09
The "signals" keyword is basically defining a "protected" section in the class definition, so your derived classes will inherit the methods you have defined as signals with protected access.

You may have to qualify the names with Page:: when you connect (and use the "PointerToMemberFunction" version of QObject::connect()).

anda_skoa
18th February 2017, 13:36
The "signals" keyword is basically defining a "protected" section in the class definition

Actually Qt5 had to switch this to "public" in order to make the function pointer based connect work.

Cheers,
_

d_stranz
18th February 2017, 20:02
Actually Qt5 had to switch this to "public" in order to make the function pointer based connect work.

Hmm, I must have been looking at older documentation. Making it public makes sense, though. Thanks for the correction.