Book Image

Application Development with Qt Creator - Second Edition

Book Image

Application Development with Qt Creator - Second Edition

Overview of this book

Table of Contents (20 chapters)
Application Development with Qt Creator Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Code interlude – signals and slots


In software systems, there is often the need to couple different objects. Ideally, this coupling should be loose, that is, not dependent on the system's compile-time configuration. This is especially obvious when you consider user interfaces, for example, a button press might adjust the contents of a text widget, or cause something to appear or disappear. Many systems use events for this purpose; components offering data encapsulate that data in an event, and an event loop (or more recently, an event listener) catches the event and performs some action. This is known as event-driven programming or the event model.

Qt offers signals and slots as the interface it uses to manage events. Like an event, the sending component generates a signal—in Qt parlance, the object emits a signal, which is an occurrence of an event—which recipient objects may execute a slot for the purpose. Qt objects might emit more than one signal, and signals might carry arguments; in...