Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are "public slots:" sections still necessary in Qt5?

A simple question regarding the new signal/slot syntax in Qt5:

  • Are there still benefits for a Q_OBJECT-derived class to have public slots:sections declared?

Note: With the new syntax you're able to connect a signal to any public function of a class or directly implement a C++11 lambda (which can also call some member functions itself).

Qt's new signal/slot syntax

like image 960
FlKo Avatar asked Nov 09 '17 08:11

FlKo


People also ask

What are Qt Public slots?

In C++, public means those members that are accessible from anywhere where the object is visible, private means that members are accessible only from within other members of the same class or from their friends. But in Qt, the difference in private slots and public slots seem not to exist.

How signal and slot works in Qt?

In Qt, we have an alternative to the callback technique: We use signals and slots. A signal is emitted when a particular event occurs. Qt's widgets have many predefined signals, but we can always subclass widgets to add our own signals to them. A slot is a function that is called in response to a particular signal.

What is a slot in framework?

Slots: certain classes or methods that are defined in the framework, but are unimplemented (user must implement them), and. Hooks: certain unimplemented functional elements that user may or may not implement.


1 Answers

public slots: etc. declarations still needed for moc introspection if you are going to use the "old" connection style. With the new syntax this declarations do not make any sense, because, as you also noticed, "slots" are called directly by function pointers. "Slots" may even be a non class member functions as well.

However, you still need to declare your signals under signals: section of your class declaration.

like image 112
vahancho Avatar answered Sep 28 '22 03:09

vahancho