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
4#ifndef QCOREAPPLICATION_PLATFORM_H
5#define QCOREAPPLICATION_PLATFORM_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is part of the native interface APIs. Usage of
12// this API may make your code source and binary incompatible
13// with future versions of Qt.
14//
15
16#include <QtCore/qglobal.h>
17#include <QtCore/qnativeinterface.h>
18#include <QtCore/qcoreapplication.h>
19
20#if defined(Q_OS_ANDROID) || defined(Q_QDOC)
21#include <QtCore/qjnitypes.h>
22#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
23#include <QtCore/qfuture.h>
24#include <QtCore/qvariant.h>
25#endif
26#endif // #if defined(Q_OS_ANDROID) || defined(Q_QDOC)
27
28#if defined(Q_OS_ANDROID)
29class _jobject;
30typedef _jobject* jobject;
31#endif
32
33QT_BEGIN_NAMESPACE
34
35namespace QNativeInterface
36{
37#if defined(Q_OS_ANDROID) || defined(Q_QDOC)
38struct Q_CORE_EXPORT QAndroidApplication
39{
40 QT_DECLARE_NATIVE_INTERFACE(QAndroidApplication, 1, QCoreApplication)
41#ifdef Q_QDOC
42 static QJniObject context();
43#else
44 static QtJniTypes::Context context();
45#endif
46 static bool isActivityContext();
47 static int sdkVersion();
48 static void hideSplashScreen(int duration = 0);
49
50#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
51 static QFuture<QVariant> runOnAndroidMainThread(const std::function<QVariant()> &runnable,
52 const QDeadlineTimer timeout = QDeadlineTimer::Forever);
53
54 template <class T>
55 std::enable_if_t<std::is_invocable_v<T> && std::is_same_v<std::invoke_result_t<T>, void>,
56 QFuture<void>> static runOnAndroidMainThread(const T &runnable,
57 const QDeadlineTimer timeout = QDeadlineTimer::Forever)
58 {
59 std::function<QVariant()> func = [runnable](){ runnable(); return QVariant(); };
60 return static_cast<QFuture<void>>(runOnAndroidMainThread(func, timeout));
61 }
62#endif
63};
64#endif
65}
66
67QT_END_NAMESPACE
68
69#endif // QCOREAPPLICATION_PLATFORM_H
70

Provided by KDAB

Privacy Policy
Learn Advanced QML with KDAB
Find out more

source code of qtbase/src/corelib/kernel/qcoreapplication_platform.h