当前位置:网站首页>Connection mode of QT signal and slot connect() and the return value of emit
Connection mode of QT signal and slot connect() and the return value of emit
2022-04-23 18:15:00 【Talent、me】
emit signal() The return value of
as everyone knows ,emit It's used when sending signals , We can also use emit Return the return value after the slot function is executed .
as follows :
class testOne : public QDialog
{
Q_OBJECT
public:
explicit testOne(QWidget *parent = nullptr);
~testOne();
signals:
bool isFlag();
private:
testTwo testObject;
public slots:
};
testOne::testOne(QWidget *parent) :
QDialog(parent)
{
connect(this, SIGNAL(isFlag()), testObject, SLOT(retFlag()),Qt::BlockingQueuedConnection);
bool flag = emit isFlag();
if(flag==true){
qDebug()<<"Success!";
}else{
qDebug()<<"Fail!";
}
}
class testTwo : public QDialog
{
Q_OBJECT
public:
explicit testTwo(QWidget *parent = nullptr);
~testTwo();
private:
public slots:
bool retFlag();
};
bool testTwo::retFlag()
{
return true;
}
Of course, you can also pass values through function parameters .
The signal is connected to the slot connect() The fifth parameter of
Generally, we ignore the fifth parameter when we write the connection between the signal and the slot , Usually, the default method is to automatically connect parameters ,Qt::connectionType=Qt::AutoConnectType.
QObject::connect(sender, SIGNAL(signal()), receiver, SLOT(slot()));
const QObject *sender, // Signal sending object pointer
const char *signal, // Signal function string , Use SIGNAL()
const QObject *receiver, // Slot function object pointer
const char *member, // Slot function string , Use SLOT()
Qt::connectionType=Qt::AutoConnectType,
Qt::AutoConnection
Auto connect : Default method .
Qt::DirectConnection
Direct connection : It's equivalent to calling slot functions directly .
Qt::QueuedConnection
Queue connection : Through internal postEvent Realized . Not called in real time , Slot functions are always executed in the thread where the slot function object is located . If the signal parameter is a reference type , You will make another copy of . Thread safe .
Qt::BlockingQueuedConnection
Blocking connections : This connection mode can only be used for the thread that signals and The object of the slot function is no longer available in a thread . Through semaphores +postEvent Realized . Not called in real time , Slot functions are always executed in the thread where the slot function object is located . But after the signal , The current thread will block , Wait for the slot function to complete before continuing .
Qt::UniqueConnection
Prevent repeated connections .
Above is connect() Five connection modes , Why suddenly say these five kinds of contact information , Because I used signals and slots in a project connect(), Because the signal and slot are not in the same thread , If you use the default connection method Qt::AutoConnection Words , In different threads, the connection mode will become Qt::QueuedConnection, Will result in the use of emit signal() when , Slot functions are not called in real time , It's the end of execution emit signal(); Statement before executing the contents of the slot function . This leads to if we want to get executed emit signal() The return value of the slot function after the statement , The result is not what we want , So we need to configure the connection mode manually , If the signal and slot are in different threads , And we need to call the slot function in real time , Then you need to configure... In the fifth parameter Qt::BlockingQueuedConnection
connect(sender, SIGNAL(signal()), receiver, SLOT(slot()),Qt::BlockingQueuedConnection);
版权声明
本文为[Talent、me]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210610471487.html
边栏推荐
- 【ACM】509. Fibonacci number (DP Trilogy)
- logstash 7. There is a time problem in X. the difference between @ timestamp and local time is 8 hours
- ArcGIS table to excel exceeds the upper limit, conversion failed
- Multi thread safe reference arc of rust
- Crawling mobile game website game details and comments (MQ + multithreading)
- Map basemap Library
- A few lines of code teach you to crawl lol skin pictures
- Win1远程出现“这可能是由于credssp加密oracle修正”解决办法
- 【ACM】455. Distribute Biscuits (1. Give priority to big biscuits to big appetite; 2. Traverse two arrays with only one for loop (use subscript index -- to traverse another array))
- Robocode tutorial 3 - Robo machine analysis
猜你喜欢

re正則錶達式

Analysez l'objet promise avec le noyau dur (Connaissez - vous les sept API communes obligatoires et les sept questions clés?)

Solution to Chinese garbled code after reg file is imported into the registry
![[UDS unified diagnostic service] IV. typical diagnostic service (4) - online programming function unit (0x34-0x38)](/img/07/4814eb203dcca59416a7997bbedbf6.png)
[UDS unified diagnostic service] IV. typical diagnostic service (4) - online programming function unit (0x34-0x38)

ArcGIS table to excel exceeds the upper limit, conversion failed

QT reading and writing XML files (including source code + comments)
Scikit learn sklearn 0.18 official document Chinese version

Process management command

Hard core parsing promise object (do you know these seven common APIs and seven key questions?)

PowerDesigner various font settings; Preview font setting; SQL font settings
随机推荐
Mysql database backup command -- mysqldump
Quantexa CDI(场景决策智能)Syneo平台介绍
函数递归以及趣味问题的解决
re正则表达式
串口调试工具cutecom和minicom
Robocode Tutorial 4 - robocode's game physics
[UDS unified diagnostic service] v. diagnostic application example: Flash bootloader
登录和发布文章功能测试
ArcGIS license error -15 solution
Serialization scheme of serde - trust
Closure type of rust (difference between FN, fnmut and fnone)
Queue solving Joseph problem
In shell programming, the shell file with relative path is referenced
A few lines of code teach you to crawl lol skin pictures
Solution to Chinese garbled code after reg file is imported into the registry
C [file operation] read TXT text by line
Selenium + phantom JS crack sliding verification 2
多功能工具箱微信小程序源码
Re expression régulière
Differences between SSD hard disk SATA interface and m.2 interface (detailed summary)