轉載自:https://blog.csdn.net/liukang325
加:在main函數中寫一個定時器,並啟動
1 QTimer timer; 2 QObject::connect(&timer, &QTimer::timeout, [&]() { 3 qDebug() << "Time COOKOO *** write: " << QDateTime::currentDateTime().toString("ss.zzz"); //秒.毫秒 4 }); 5 timer.start(500);
1、最基本的,4個參數
1 //阻塞 2 QEventLoop loop; 3 QObject::connect(this, SIGNAL(getRtmpCodeFinished()), &loop, SLOT(quit())); 4 loop.exec();
1 QPointer<QAction> sysTrayReplayBuffer; 2 ... 3 connect(sysTrayReplayBuffer.data(), &QAction::triggered, this, &HBasic::ReplayBufferClicked);
2、lamda表達式
注:
[a,&b] a變量以值的方式唄捕獲,b以引用的方式被捕獲;
[this] 以值的方式捕獲 this 指針;
[&] 以引用的方式捕獲所有的外部自動變量(包括this);
[=] 以值的方式捕獲所有的外部自動變量(包括this);
[] 不捕獲外部的任何變量。
1 HLiveSettings liveSetting(this); 2 auto getRtmpCodeSlots = [&](QString rtmpStr) { 3 QDBG << rtmpStr; 4 ... 5 }; 6 connect(&liveSetting, &HLiveSettings::getRtmpCode, getRtmpCodeSlots);
1 auto clickedSlots = [this]() { 2 ... 3 }; 4 connect(ui->pushbutton, &QPushButton::clicked, clickedSlots);
1 m_downLoadManagerForImage = new DownLoadManager(this); 2 connect(m_downLoadManagerForImage, &DownLoadManager::FileDownloadFinished, [=]() 3 { 4 QDBG << "FileDownloadFinished!"; 5 addPendantSource("test"); 6 });