I would like to know if the function do_something()
is treated as a new thread, when I click on my_button
.
connect(my_button, SIGNAL(clicked), this, SLOT(do_something));
I would like to know if the function do_something()
is treated as a new thread, when I click on my_button
.
connect(my_button, SIGNAL(clicked), this, SLOT(do_something));
The typical signal/slot behavior is determined based on the connection type. When unspecified, it defaults to Qt::AutoConnection
and will use the receiver's thread if a direct connection can't be made.
From the docs:
The slot is invoked when control returns to the event loop of the receiver's thread. The slot is executed in the receiver's thread.
You can change the connection type at connect time to alter the behavior:
connect(my_button, SIGNAL(clicked), this, SLOT(do_something),
Qt::QueuedConnection); // always queue
Since you're talking about a button that's emitting the signal, the default connection type of Qt::AutoConnection
implies that a direct connection is made and that the do_something
slot will be executed immediately as if it had been called directly at the point the button was clicked.
© 2022 - 2024 — McMap. All rights reserved.