화면 캡처 예시
화면 또는 창 캡처.
'화면 캡처' 예제는 ` QScreenCapture ` 및 ` QWindowCapture`을 사용하여 화면이나 창을 캡처하는 방법을 보여줍니다. 이 예제에서는 화면 및 창 목록을 표시하고, ` QMediaCaptureSession ` 및 ` QVideoWidget`을 사용하여 선택한 항목의 실시간 미리보기를 표시합니다. 캡처는 ` button`을 사용하여 시작 및 중지할 수 있습니다.

예제 실행
다음 경로에서 예제를 실행할 수 있습니다:
- Qt Creator
Welcome 모드를 열고 Examples 에서 예제를 선택합니다. 자세한 내용은 Qt Creator: 튜토리얼: 빌드 및 실행을 참조하십시오.
- Qt Extension for Visual Studio Code
Command Palette 에서 Qt: Open Qt examples 명령을 실행하고 목록에서 예제를 선택하십시오. 자세한 내용은 Qt Extension for Visual Studio Code: 튜토리얼: 빌드 및 실행을 참조하십시오.
애플리케이션 구조
이 예제는 세 개의 사용자 정의 클래스로 구성되어 있습니다. UI와 모든 화면 캡처 기능은 ScreenCapturePreview 클래스에서 구현됩니다. ScreenListModel 및 WindowListModel 클래스는 두 개의 QListView 위젯을 뒷받침하는 모델 역할만 합니다. main 함수는 ScreenCapturePreview 객체를 생성하며, 이 객체는 QScreenCapture 및 QWindowCapture 의 인스턴스와 QMediaCaptureSession 및 QVideoWidget 의 인스턴스를 생성하고, 모든 UI 위젯을 생성합니다.
스크린 및 윈도우 모델은 각각 ` QGuiApplication::screens()` 및 ` QWindowCapture::capturableWindows()`의 반환값으로 채워집니다.
목록 항목이 선택되면, setScreen()을 통해 QScreenCapture 객체에 연결되거나, setWindow()을 통해 QWindowCapture 객체에 연결됩니다. 캡처 객체는 setScreenCapture() 및 setWindowCapture()을 통해 각각 QMediaCaptureSession 객체에 연결됩니다. 캡처 세션은 차례로 setVideoOutput()를 통해 QVideoWidget 객체에 연결됩니다. 따라서 캡처된 영상은 UI 우측의 비디오 위젯에서 미리 볼 수 있습니다.
시작/중지 버튼은 QScreenCapture::start() 및 QScreenCapture::stop()을 호출하거나, QWindowCapture::start() 및 QWindowCapture::stop()을 호출합니다.
errorOccurred 신호가 발생하면 QMessageBox 이 팝업으로 표시됩니다.
© 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.