QT connect的多种写法

论坛 期权论坛 脚本     
匿名网站用户   2020-12-21 11:19   2314   0

1. 最基本的, 4个参数

//阻塞
QEventLoop loop;
QObject::connect(this, SIGNAL(getRtmpCodeFinished()), &loop, SLOT(quit()));
loop.exec();
QPointer<QAction> sysTrayReplayBuffer;
...
connect(sysTrayReplayBuffer.data(), &QAction::triggered, this, &HBasic::ReplayBufferClicked);

2. lamda表达试

HLiveSettings liveSetting(this);
auto getRtmpCodeSlots = [&](QString rtmpStr) {
    QDBG << rtmpStr;
    ...
};
connect(&liveSetting, &HLiveSettings::getRtmpCode, getRtmpCodeSlots);
auto clickedSlots = [this]() {
    ...
};
connect(ui->pushbutton, &QPushButton::clicked, clickedSlots);
m_downLoadManagerForImage = new DownLoadManager(this);
connect(m_downLoadManagerForImage, &DownLoadManager::FileDownloadFinished, [=]()
{
    QDBG << "FileDownloadFinished!";
    addPendantSource("test");
});

[a,&b] a变量以值的方式呗捕获,b以引用的方式被捕获。
[this] 以值的方式捕获 this 指针。
[&] 以引用的方式捕获所有的外部自动变量(包括this)。
[=] 以值的方式捕获所有的外部自动变量(包括this)。
[] 不捕获外部的任何变量。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:1136255
帖子:227251
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP