Custom signals
In previous chapters, we saw how to use slots and create custom slots to implement some functionality in response to a signal being emitted. Now, in this section, we will look at how to create custom signals that can be emitted and connected to other slots.
To create a custom signal, one needs to declare a method signature and mark it as a signal with the aid of the Q_OBJECT macro. When declared, signals don't have a return type, but they can accept parameters.
Let's get our feet wet with a project. As usual, a new folder should be created with the three (3) files, namely, main.cpp, mainwindow.cpp, and mainwindow.h.
In this example, we shall override mousePressEvent and emit a custom signal that will be connected to a slot ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access