147bool QDesktopServices::openUrl(
const QUrl &url)
149 QOpenUrlHandlerRegistry *registry = handlerRegistry();
150 QMutexLocker locker(®istry->mutex);
151 static bool insideOpenUrlHandler =
false;
153 if (!insideOpenUrlHandler) {
154 QOpenUrlHandlerRegistry::HandlerHash::ConstIterator handler = registry->handlers.constFind(url.scheme());
155 if (handler != registry->handlers.constEnd()) {
156 insideOpenUrlHandler =
true;
157 bool result = QMetaObject::invokeMethod(handler->receiver, handler->name.constData(), Qt::DirectConnection, Q_ARG(QUrl, url));
158 insideOpenUrlHandler =
false;
165 QPlatformIntegration *platformIntegration = QGuiApplicationPrivate::platformIntegration();
166 if (Q_UNLIKELY(!platformIntegration)) {
167 QCoreApplication *application = QCoreApplication::instance();
168 if (Q_UNLIKELY(!application))
169 qWarning(
"QDesktopServices::openUrl: Please instantiate the QGuiApplication object "
171 else if (Q_UNLIKELY(!qobject_cast<QGuiApplication *>(application)))
172 qWarning(
"QDesktopServices::openUrl: Application is not a GUI application");
176 QPlatformServices *platformServices = platformIntegration->services();
177 if (!platformServices) {
178 qWarning(
"The platform plugin does not support services.");
183 if (url.isLocalFile() && !url.hasFragment() && !url.hasQuery())
184 return platformServices->openDocument(url);
185 return platformServices->openUrl(url);
273void QDesktopServices::setUrlHandler(
const QString &scheme, QObject *receiver,
const char *method)
275 QOpenUrlHandlerRegistry *registry = handlerRegistry();
276 QMutexLocker locker(®istry->mutex);
278 registry->handlers.remove(scheme.toLower());
281 QOpenUrlHandlerRegistry::Handler h;
282 h.receiver = receiver;
284 registry->handlers.insert(scheme.toLower(), h);