Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcoreapplication_platform.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QCOREAPPLICATION_PLATFORM_H
6#define QCOREAPPLICATION_PLATFORM_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is part of the native interface APIs. Usage of
13// this API may make your code source and binary incompatible
14// with future versions of Qt.
15//
16
17#include <QtCore/qglobal.h>
18#include <QtCore/qnativeinterface.h>
19#include <QtCore/qcoreapplication.h>
20
21#if defined(Q_OS_ANDROID) || defined(Q_QDOC)
22#include <QtCore/qjnitypes.h>
23#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
24#include <QtCore/qfuture.h>
25#include <QtCore/qvariant.h>
26#endif
27#endif // #if defined(Q_OS_ANDROID) || defined(Q_QDOC)
28
29#if defined(Q_OS_ANDROID)
30class _jobject;
31typedef _jobject* jobject;
32#endif
33
34QT_BEGIN_NAMESPACE
35
36namespace QNativeInterface
37{
38#if defined(Q_OS_ANDROID) || defined(Q_QDOC)
39struct Q_CORE_EXPORT QAndroidApplication
40{
41 QT_DECLARE_NATIVE_INTERFACE(QAndroidApplication, 1, QCoreApplication)
42#ifdef Q_QDOC
43 static QJniObject context();
44#else
45 static QtJniTypes::Context context();
46#endif
47 static bool isActivityContext();
48 static int sdkVersion();
49 static void hideSplashScreen(int duration = 0);
50
51#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
52 static QFuture<QVariant> runOnAndroidMainThread(const std::function<QVariant()> &runnable,
53 const QDeadlineTimer timeout = QDeadlineTimer::Forever);
54
55 template <class T>
56 std::enable_if_t<std::is_invocable_v<T> && std::is_same_v<std::invoke_result_t<T>, void>,
57 QFuture<void>> static runOnAndroidMainThread(const T &runnable,
58 const QDeadlineTimer timeout = QDeadlineTimer::Forever)
59 {
60 std::function<QVariant()> func = [runnable](){ runnable(); return QVariant(); };
61 return static_cast<QFuture<void>>(runOnAndroidMainThread(func, timeout));
62 }
63#endif
64};
65#endif
66}
67
68QT_END_NAMESPACE
69
70#endif // QCOREAPPLICATION_PLATFORM_H