Qt Signal And Slots

  • Differences between String-Based and Functor-Based Connections (Official documentation)
  • Introduction (Woboq blog)
  • Implementation Details (Woboq blog)
  • 1Connecting in Qt 5
  • 2Disconnecting in Qt 5
  • 4Error reporting
  • 5Open questions

Connecting in Qt 5

Old syntax

New: connecting to QObject member

Pros

  • Compile time check of the existence of the signals and slot, of the types, or if the Q_OBJECT is missing.
  • Argument can be by typedefs or with different namespace specifier, and it works.
  • Possibility to automatically cast the types if there is implicit conversion (e.g. from QString to QVariant)
  • It is possible to connect to any member function of QObject, not only slots.

Cons

  • More complicated syntax? (you need to specify the type of your object)
  • Very complicated syntax in cases of overloads? (see below)
  • Default arguments in slot is not supported anymore.

New: connecting to simple function

Pros

  • Can be used with std::bind:
  • Can be used with C++11 lambda expressions:

Cons

  • There is no automatic disconnection when the ‘receiver’ is destroyed because it’s a functor with no QObject. However, since 5.2 there is an overload which adds a ‘context object’. When that object is destroyed, the connection is broken (the context is also used for the thread affinity: the lambda will be called in the thread of the event loop of the object used as context).

Disconnecting in Qt 5

Qt signal and slots

Old way

Signal
  • You connected using the old way, or
  • If you want to disconnect all the slots from a given signal using wild card character

Symetric to the function pointer one

New way using QMetaObject::Connection

Asynchronous made easier

Error reporting

Missing Q_OBJECT in class definition

Qt Connect Slot

Type mismatch

Open questions

Default arguments in slot

Overload

All games i have played

Qt Signals And Slots Between Classes

Disconnect

Signal And Slots In Qt

Callbacks

Qt Signal And Slots

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Spacecrafts With Explosive Engines: How to Survive a Fight With Technical Debt

Computing PI in Only 3 Lines

SIP ( Session Initiation Protocol )

How to Set Up Python in VSCode

Design Pattern in Java — Visitor pattern

Random, Empty Notification Pop-Ups in Ubuntu, and How I Fixed That

Ubuntu notification popup.

Meta/Microsoft/Amazon — 173. Binary Search Tree Iterator

LeetCode topics — Tree

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
lyloto

lyloto

More from Medium

Drilling activity and hydrocarbon output are on the rise in the US shale plays, greatly…

Capsule Review: Factfulness

Install Cloudwatch Agent install in the Elasticbeanstalk Environment

WordArt 1/30