150bool QDesktopServices::openUrl(
const QUrl &url)
152 QOpenUrlHandlerRegistry *registry = handlerRegistry();
153 QMutexLocker locker(®istry->mutex);
154 static bool insideOpenUrlHandler =
false;
156 if (!insideOpenUrlHandler) {
157 QOpenUrlHandlerRegistry::HandlerHash::ConstIterator handler = registry->handlers.constFind(url.scheme());
158 if (handler != registry->handlers.constEnd()) {
159 insideOpenUrlHandler =
true;
160 bool result = QMetaObject::invokeMethod(handler->receiver, handler->name.constData(), Qt::DirectConnection, Q_ARG(QUrl, url));
161 insideOpenUrlHandler =
false;
168 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
169 if (Q_UNLIKELY(!platformIntegration)) {
170 QCoreApplication *application = QCoreApplication::instance();
171 if (Q_UNLIKELY(!application))
172 qWarning(
"QDesktopServices::openUrl: Please instantiate the QGuiApplication object "
174 else if (Q_UNLIKELY(!qobject_cast<QGuiApplication *>(application)))
175 qWarning(
"QDesktopServices::openUrl: Application is not a GUI application");
179 QPlatformServices *platformServices = platformIntegration->services();
180 if (!platformServices) {
181 qWarning(
"The platform plugin does not support services.");
186 if (url.isLocalFile() && !url.hasFragment() && !url.hasQuery())
187 return platformServices->openDocument(url);
188 return platformServices->openUrl(url);
276void QDesktopServices::setUrlHandler(
const QString &scheme, QObject *receiver,
const char *method)
278 QOpenUrlHandlerRegistry *registry = handlerRegistry();
279 QMutexLocker locker(®istry->mutex);
281 registry->handlers.remove(scheme.toLower());
284 QOpenUrlHandlerRegistry::Handler h;
285 h.receiver = receiver;
287 registry->handlers.insert(scheme.toLower(), h);