21,468
社区成员
发帖
与我相关
我的任务
分享
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 有多种参数的重载
一般我只用它的 QMetaObject::invokeMethod(this, "mySlot") 这一重载
目的是为了通过不同的字符串(比如“mySlot”)调用不同的函数,也就是所谓的“反射”
文中的重载很少使用
Qt 公司是为了保持 API 的一致才加入的这种重载函数
文中代码不全,所以只能分析如下
如果 CustomCefView 在主线程,那么直接调用 QMessageBox::information 就可以,没必要 QMetaObject::invokeMethod
如果 CustomCefView 在别的线程,那么我一般 emit 一个信号,通知主线程来处理,也同样不会使用到 QMetaObject::invokeMethod