16,213
社区成员
发帖
与我相关
我的任务
分享
bool QDesktopServices::openUrl(const QUrl &url)
{
QOpenUrlHandlerRegistry *registry = handlerRegistry();
QMutexLocker locker(®istry->mutex);
static bool insideOpenUrlHandler = false;
if (!insideOpenUrlHandler) {
QOpenUrlHandlerRegistry::HandlerHash::ConstIterator handler = registry->handlers.constFind(url.scheme());
if (handler != registry->handlers.constEnd()) {
insideOpenUrlHandler = true;
bool result = QMetaObject::invokeMethod(handler->receiver, handler->name.constData(), Qt::DirectConnection, Q_ARG(QUrl, url));
insideOpenUrlHandler = false;
return result; // ### support bool slot return type
}
}
if (!url.isValid())
return false;
QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
if (!platformIntegration)
return false;
QPlatformServices *platformServices = platformIntegration->services();
if (!platformServices) {
qWarning("%s: The platform plugin does not support services.", Q_FUNC_INFO);
return false;
}
return url.scheme() == QLatin1String("file") ?
platformServices->openDocument(url) : platformServices->openUrl(url);
}
void MainWindow::OnAct(bool)
{
QAction* act = (QAction*)sender();
act->setEnabled(false);//置灰按钮
qDebug()<<"currentThreadId:"<<QThread::currentThreadId();
QString url ("E:/abc.txt");
bool bOk = QDesktopServices::openUrl(QUrl(url, QUrl::StrictMode));
qDebug()<<"end";
act->setEnabled(true);//放开按钮点击
}