39#ifdef QT_UTILITIES_OPEN_VIA_ACTIVITY
40 if (
const auto context = QNativeInterface::QAndroidApplication::context(); context.isValid()) {
41 auto env = QJniEnvironment();
42 if (
auto openPathMethod = env.findMethod(context.objectClass(),
"openPath",
"(Ljava/lang/String;)Z")) {
43 return env->CallBooleanMethod(context.object(), openPathMethod, QJniObject::fromString(path).object()) == JNI_TRUE;
48 QUrl url(QStringLiteral(
"file://"));
53 tmp.replace(QChar(
'\\'), QChar(
'/'));
56 if (QFileInfo(path).isAbsolute()) {
57 tmp = QStringLiteral(
"/") + tmp;
59 url.setPath(tmp, QUrl::DecodedMode);
62 url.setPath(path, QUrl::DecodedMode);
64 return QDesktopServices::openUrl(url);
102QMetaObject::Connection
onDarkModeChanged(std::function<
void(
bool)> &&darkModeChangedCallback, QObject *context,
bool invokeImmediately)
104#if (QT_VERSION >= QT_VERSION_CHECK(6, 5, 0))
105 if (
const auto *
const styleHints = QGuiApplication::styleHints()) {
106 if (invokeImmediately) {
107 darkModeChangedCallback(styleHints->colorScheme() == Qt::ColorScheme::Dark);
109 return QObject::connect(styleHints, &QStyleHints::colorSchemeChanged, context,
110 [handler = std::move(darkModeChangedCallback)](Qt::ColorScheme colorScheme) {
return handler(colorScheme == Qt::ColorScheme::Dark); });
113 Q_UNUSED(darkModeChangedCallback)
115 Q_UNUSED(invokeImmediately)
117 return QMetaObject::Connection();
QT_UTILITIES_EXPORT QMetaObject::Connection onDarkModeChanged(std::function< void(bool)> &&darkModeChangedCallback, QObject *context=nullptr, bool invokeImmediately=true)
Invokes the specified callback when the color scheme changed.