Signal Slot Qt5

Signal Slot Qt5 Rating: 4,4/5 7037 votes
  1. Qt5 Signal Slot Arguments
  2. Signal Slot Qt With Param
Qt5

Hi People,

Qt5插件使用信号槽机制通信 / Qt 5 plugin with signal-slots. Contribute to 3dBPoint/Qt5PluginSignalSlots development by creating an account on GitHub. For example, a signal&slot for making a signal&slot. App.exec run a loop but not run init over and over again. App.exec is waiting for user input, eventHandler, for example, keyPressEvent, mousePressEvent. Especially, paintEvent for showing the GUI. Init is only called once. The variables of it are allotted into your computer's.

This is the sequel of my previous article explaining the implementation details of the signals and slots. In the Part 1, we have seen the general principle and how it works with the old syntax. In this blog post, we will see the implementation details behind the new function pointer based syntax in Qt5.

Qt5 signal slot syntax

I have a problem with Qt meta-type system and the signal and slot connections.
I try to connect a signal and slot with each other. The signal looks like this:

@
signals: void sigSaveFileName(QString&);
@

and the slot:
@
private slots: void slotPutSaveFileName(QString& name);
@

Before I connect those, I would like register the QString with qRegisterMetaType() method then call connect method:

@
qRegisterMetaType<QString>('QString');
connect(&_worker, &Worker::sigOpenFileName, this, &MainWindow::slotPutOpenFileName);
@

If I run my application, I watch the application output, and I get the following warning:
QObject::connect: Cannot queue arguments of type 'QString&'
(Make sure 'QString&' is registered using qRegisterMetaType().)
QObject::connect: Cannot queue arguments of type 'QString&'
(Make sure 'QString&' is registered using qRegisterMetaType().)

and doesn't happen anything :(

Can tell me somebody what I make wrong?

Regards,
Norbert

Graphical applications (GUI) are event-driven, unlike console or terminal applications. A users action like clicks a button or selecting an item in a list is called an event.

If an event takes place, each PyQt5 widget can emit a signal. A signal does not execute any action, that is done by a slot.

Related course:
Create GUI Apps with PyQt5

Signals and slot introduction
Consider this example:

Qt5

The button click (signal) is connected to the action (slot). In this example, the method slot_method will be called if the signal emits.

This principle of connecting slots methods or function to a widget, applies to all widgets,

Qt5 Signal Slot Arguments

or we can explicitly define the signal:

PyQt supports many type of signals, not just clicks.

Example
We can create a method (slot) that is connected to a widget. A slot is any callable function or method.

On running the application, we can click the button to execute the action (slot).

Qt5

Signal Slot Qt With Param

If you are new to programming Python PyQt, I highly recommend this book.