이 페이지에서

네이티브 인터페이스

네이티브 인터페이스는 상속받는 클래스의 네이티브 또는 플랫폼별 API에 대한 액세스를 제공합니다.

이 인터페이스들은 QNativeInterface 네임스페이스에 속하며, 기본이 되는 네이티브 핸들에 대한 액세스, 기존 네이티브 핸들의 채택, 플랫폼별 API 제공과 같은 사용 사례를 다룹니다.

사용 예

기본 네이티브 핸들 액세스

Qt에서 네이티브 플랫폼의 특정 기능이 노출되지 않는 경우, Qt가 관리하는 네이티브 핸들에 접근하여 이를 통해 네이티브 API를 호출하는 것이 유용할 수 있습니다.

예를 들어, macOS에서 QNativeInterface::QCocoaGLContext 네이티브 인터페이스를 통해 QOpenGLContext 의 기본 NSOpenGLContext에 접근하려면 다음과 같이 합니다:

using namespace QNativeInterface;
if (auto *cocoaGLContext = glContext->nativeInterface<QCocoaGLContext>())
    [cocoaGLContext->nativeContext() makeCurrentContext];

네이티브 인터페이스는 QOpenGLContext::nativeInterface() 액세서를 통해 접근할 수 있으며, 이 액세서는 요청된 인터페이스가 사용 가능한지 확인하고, 그렇지 않은 경우 nullptr 를 반환합니다. 그런 다음 nativeContext() 액세서를 통해 기본 NSOpenGLContext에 접근할 수 있습니다.

기존 네이티브 핸들 채택

어떤 상황에서는 네이티브 플랫폼이나 다른 툴킷이 생성한 네이티브 핸들을 Qt로 전달하고자 할 수 있습니다. 즉, 새로운 핸들을 생성하는 대신 기존 핸들을 래핑하는 것입니다.

예를 들어, 기존 NSOpenGLContext를 채택하여 Qt에서 생성한 컨텍스트와 리소스를 공유하려면 다음과 같이 합니다.

using namespace QNativeInterface;
QOpenGLContext *adoptedContext = QCocoaGLContext::fromNativeContext(nsOpenGLContext);
anotherContext->setShareContext(adoptedContext);

인수된 컨텍스트는 QNativeInterface::QCocoaGLContext 네이티브 인터페이스의 플랫폼별 팩토리 함수를 통해 생성됩니다.

플랫폼별 API에 접근하기

어떤 경우에는 API가 플랫폼에 지나치게 특화되어 있어 크로스 플랫폼 Qt 클래스에 포함할 수는 없지만, 포함하는 것이 여전히 유용할 때가 있습니다. 이러한 API는 기본 네이티브 핸들에 접근할 때와 동일한 방식으로, 즉 ` nativeInterface()` 액세서를 통해, 또는 네이티브 인터페이스의 정적 함수로 직접 사용할 수 있습니다.

예를 들어, Windows에서 OpenGL 모듈 핸들을 추출하려면 다음과 같이 합니다.

using namespace QNativeInterface;
HMODULE moduleHandle = QWGLContext::openGLModuleHandle();

소스 및 바이너리 호환성

네이티브 인터페이스 API에 대해서는 소스 또는 바이너리 호환성이 보장되지 않습니다. 즉, 이러한 인터페이스를 사용하는 애플리케이션은 개발 시 사용된 Qt 버전에서만 작동이 보장됩니다.

사용 가능한 인터페이스

사용 가능한 모든 인터페이스 목록은 QNativeInterface 네임스페이스를 참조하십시오.

QOpenGLContext

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

QNativeInterface::QCocoaGLContext

macOS의 NSOpenGLContext에 대한 네이티브 인터페이스

QNativeInterface::QEGLContext

EGL 컨텍스트에 대한 네이티브 인터페이스

QNativeInterface::QGLXContext

GLX 컨텍스트에 대한 네이티브 인터페이스

QNativeInterface::QWGLContext

Windows에서 WGL 컨텍스트에 대한 네이티브 인터페이스

QOffscreenSurface

QOffscreenSurface::nativeInterface()을 통해 액세스합니다.

QNativeInterface::QAndroidOffscreenSurface

Android의 오프스크린 서페이스에 대한 네이티브 인터페이스

QSGTexture

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

QNativeInterface::QSGD3D11Texture

Direct3D 11 텍스처 객체에 대한 액세스를 제공하고 이를 채택할 수 있게 합니다.

QNativeInterface::QSGD3D12Texture

Direct3D 12 텍스처 객체에 대한 액세스를 제공하고 이를 채택할 수 있게 합니다.

QNativeInterface::QSGMetalTexture

Metal 텍스처 객체에 대한 액세스를 제공하고 이를 채택할 수 있게 합니다.

QNativeInterface::QSGOpenGLTexture

OpenGL 텍스처 객체에 대한 액세스를 제공하고 이를 채택할 수 있게 합니다.

QNativeInterface::QSGVulkanTexture

Vulkan 이미지 객체에 대한 액세스를 제공하고 이를 채택할 수 있도록 합니다.

© 2026 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.