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)。
[] 不捕获外部的任何变量。