QAndroidApplication Struct

struct QNativeInterface::QAndroidApplication

Android의 핵심 애플리케이션에 대한 기본 인터페이스입니다. 더 보기...

Header: #include <QCoreApplication>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
이후: Qt 6.2

정적 공용 멤버

(since 6.2) QJniObject context()
(since 6.2) void hideSplashScreen(int duration = 0)
(since 6.2) bool isActivityContext()
(since 6.2) QFuture<QVariant> runOnAndroidMainThread(const std::function<QVariant ()> &runnable, const QDeadlineTimer timeout = QDeadlineTimer::Forever)
(since 6.2) int sdkVersion()

상세 설명

QCoreApplication::nativeInterface()를 통해 액세스합니다.

멤버 함수 문서

[static, since 6.2] QJniObject QAndroidApplication::context()

가장 최근에 시작한 활동 개체가 유효한 경우 안드로이드 컨텍스트를 QJniObject 로 반환합니다. 컨텍스트는 Activity 입니다. 그렇지 않으면 컨텍스트는 Service 입니다.

이 함수는 Qt 6.2에 도입되었습니다.

[static, since 6.2] void QAndroidApplication::hideSplashScreen(int duration = 0)

주어진 duration 에 페이드 효과를 사용하여 스플래시 화면을 숨깁니다. duration 을 제공하지 않으면(기본값은 0) 앱이 시작되는 즉시 스플래시 화면이 숨겨집니다.

이 기능은 Qt 6.2에 도입되었습니다.

[static, since 6.2] bool QAndroidApplication::isActivityContext()

QAndroidApplication::context()가 Activity 컨텍스트를 제공하면 true 을 반환합니다.

이 함수는 Qt 6.2에 도입되었습니다.

[static, since 6.2] QFuture<QVariant> QAndroidApplication::runOnAndroidMainThread(const std::function<QVariant ()> &runnable, const QDeadlineTimer timeout = QDeadlineTimer::Forever)

runnable 함수를 Android 스레드에 게시합니다. 함수는 안드로이드 UI 스레드에서 큐에 대기하고 실행됩니다. Android UI 스레드에서 호출이 이루어지면 runnable 이 즉시 실행됩니다. Android 앱이 일시 중지되었거나 기본 활동이 null인 경우 runnable 이 Android 메인 스레드의 대기열에 추가됩니다.

이 호출은 QFuture<QVariant>을 반환하며, 동기 및 비동기 호출을 모두 수행할 수 있고 모든 반환 유형을 처리할 수 있습니다. 그러나 QFuture::result()에서 결과를 반환하려면 QVariant::value()을 사용해야 합니다.

runnable 실행이 timeout 의 기간보다 오래 걸리는 경우 차단 호출 QFuture::waitForFinished() 및 QFuture::result()은 timeout 이 경과하면 종료됩니다. 그러나 runnable 이 이미 실행을 시작한 경우에는 취소되지 않습니다.

다음 예는 반환 유형을 기대하는 비동기 호출을 실행하는 방법을 보여줍니다:

auto task = QNativeInterface::QAndroidApplication::runOnAndroidMainThread([=]() { QJniObject surfaceView; if (!surfaceView.isValid())        qDebug() << "SurfaceView object is not valid yet";

    surfaceView = QJniObject("android/view/SurfaceView", "(Landroid/content/Context;)V", QNativeInterface::QAndroidApplication::context()); return QVariant::fromValue(surfaceView); }).then([](QFuture<QVariant> future) { auto surfaceView = future.result().value<QJniObject>(); if (surfaceView.isValid())        qDebug() << "Retrieved SurfaceView object is valid";
});

다음 예제는 무효 반환 유형으로 동기 호출을 실행하는 방법을 보여줍니다:

QNativeInterface::QAndroidApplication::runOnAndroidMainThread([]() {
   QJniObject activity = QNativeInterface::QAndroidApplication::context();
   // Hide system ui elements or go full screen
   activity.callObjectMethod("getWindow", "()Landroid/view/Window;")
           .callObjectMethod("getDecorView", "()Landroid/view/View;")
           .callMethod<void>("setSystemUiVisibility", "(I)V", 0xffffffff);
}).waitForFinished();

참고: 긴 연산은 앱의 UI 렌더링 및 입력 처리를 차단할 수 있으므로 안드로이드의 메인 스레드에서 수행하는 연산 유형에 주의해야 합니다. 함수의 실행 시간이 길 것으로 예상되는 경우 runnable 에서 QDeadlineTimer 을 사용하여 실행을 관리하고 UI 스레드를 차단하지 않도록 하는 것도 좋습니다. 일반적으로 5초가 넘는 작업은 앱의 UI를 차단할 수 있습니다. 자세한 내용은 앱 반응성 유지를 참조하세요.

이 기능은 Qt 6.2에 도입되었습니다.

[static, since 6.2] int QAndroidApplication::sdkVersion()

안드로이드 SDK 버전을 반환합니다. 이를 API 레벨이라고도 합니다.

이 함수는 Qt 6.2에 도입되었습니다.

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.