Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Getting Started with Qt 5

You're reading from   Getting Started with Qt 5 Introduction to programming Qt 5 for cross-platform application development

Arrow left icon
Product type Paperback
Published in Feb 2019
Publisher Packt
ISBN-13 9781789956030
Length 136 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Benjamin Baka Benjamin Baka
Author Profile Icon Benjamin Baka
Benjamin Baka
Arrow right icon
View More author details
Toc

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 to perform a number of updates on a window.

In the mainwindow.h file, insert the following lines of code:

#ifndef MAINWINDOW_H
#define...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image