Skip to content

CopperSpice Journal

CopperSpice Journal

Signals and Slots

Posted on January 3, 2022January 10, 2022 By Barbara Geller

In a GUI program there are many times when the application needs to do something in response to a recent action take by the user. For example, if a user clicks a close button they probably want to close the corresponding window. In the design of the program it would be nice to have a simple mechanism connecting the mouse click to the close() method.

In CopperSpice this mechanism is implemented using a Signal / Slot relationship. A signal is emitted when a particular event occurs, such as the mouse click. A slot is usually a normal method which is called in response to the event.

Signals and Slots are used for communication between objects.

Technical Overview

The signal and slot system is type safe and works across threads. The signal may emit any number of parameters of any copyable data type. The slot can ignore any or all of these parameters. The only constraint is that if the slot needs to receive some of the parameters the order must match those emitted by the signal.

A class which emits a signal does not need to know which slots receive the signal. All classes that inherit from QObject or one of its subclasses can contain signals and slots.

Uncategorized

Post navigation

Previous Post: Source Code  (Gui Example 3)
Next Post: Source Code  (Gui Example 4)
  • CopperSpice Journal Homepage
    • Table of Contents
    • Example Source Code
    • Discussion Forum
  • CopperSpice Homepage
  • Github Repository
  • Videos About C++

Post comments or questions on our CopperSpice Forum

Copyright © 2021-2025 CopperSpice