看到一段Qt代碼,如下:
void
CustomCefView::onQCefUrlRequest(const QString& url)
{
QString title("QCef Url Request");
QString text = QString("Current Thread: QT_UI\r\n"
"Url: %1")
.arg(url);
QMetaObject::invokeMethod(this, [=]() {
QMessageBox::information(this->window(), title, text);
}, Qt::QueuedConnection);
}
QMetaObject::invokeMethod(this, [=]() {
QMessageBox::information(this->window(), title, text);
}, Qt::QueuedConnection); 這句代碼怎么理解呢?QMetaObject::invokeMethod(this, [=]() 這個是什么用法呢?
uj5u.com熱心網友回復:
這個用法就是把這段lambda扔到主執行緒的事件佇列里,而不是直接在這個方法里面執行這樣就算現在這個方法被呼叫時不在主執行緒,但這個lambda被執行時肯定在主執行緒
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/270183.html
標籤:Qt
