A
A
Alexey2014-06-17 22:03:50
Qt
Alexey, 2014-06-17 22:03:50

Is there some C++ notification/signal mechanism similar to Qt?

Good day!
For quite a long time I have been writing in Qt, which provides a very convenient signal-slot mechanism. Tell me, is it possible to write at least something remotely resembling in pure C ++? Without Win API.
Let's say there is a DLL that provides a singleton class. It is necessary that after a call on an instance of this class of a certain function, a certain "signal" is sent, which has defined types of transmitted values.
On Qt it would look like this:

class Singleton : public QObject
{
    Q_OBJECT
public:
    void function(const QString& arg)
    { emit broadcast(arg); }
signals:
    void broadcast(const QString& arg);
}

When the function function is called, a broadcast signal will be sent, to which, in turn, everyone who owns an instance of this class can connect. Can this mechanism be implemented in C++? As a last resort, you can use WinAPI.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
Lolshto, 2014-06-17
@Renzo

Generally speaking, you are interested in the Observer
design pattern. A large number of implementations can be invented
* In WinAPI using the message system
* In C using function pointers
* In C ++ using std::function or any other object, interface which is known
* In C++ using boost::signals
* Qt signals/slots
* etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question