QFileOpenEvent Class
QFileOpenEvent 클래스는 파일 또는 URL을 열라는 요청이 있을 때 전송되는 이벤트를 제공합니다. 더 보기...
| 헤더: | #include <QFileOpenEvent> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui)target_link_libraries(mytarget PRIVATE Qt6::Gui) |
| qmake: | QT += gui |
| 상속합니다: | QEvent |
- 상속된 멤버를 포함한 모든 멤버 목록
- 사용되지 않는 멤버
- QFileOpenEvent는 이벤트 클래스의 일부입니다.
공용 함수
상세 설명
파일 열기 이벤트는 운영 체제에서 파일 또는 URL을 열어야 한다고 요청할 때 QApplication::instance()로 전송됩니다. 이 이벤트는 플랫폼에 따라 다양한 사용자 작업으로 인해 발생할 수 있는 상위 수준의 이벤트로, 예를 들어 Finder에서 파일을 두 번 클릭하거나 macOS에서 파일을 애플리케이션의 Dock 아이콘으로 드래그하거나 iOS에서 다른 애플리케이션의 파일을 공유하는 등의 작업을 수행합니다.
이 이벤트는 애플리케이션에 요청을 알리는 데만 사용됩니다. 파일을 열지 않아야 하는 경우에는 안전하게 무시할 수 있습니다.
Apple 플랫폼
Apple 플랫폼에서 이벤트를 트리거하려면 애플리케이션이 어떤 종류의 파일에 반응해야 하는지 OS에 알려주도록 애플리케이션을 구성해야 합니다.
예를 들어, 다음 Info.plist 파일은 애플리케이션이 PNG 파일의 뷰어 역할을 할 수 있음을 선언합니다:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>LSItemContentTypes</key>
<array>
<string>public.png</string>
</array>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
</dict>
</array>
</dict>
</plist>iOS에서 애플리케이션이 파일 애플리케이션 등에서 '연결 프로그램' 동작으로 표시되려면 다음 키도 필요합니다:
<key>UISupportsDocumentBrowser</key> <true/>
다음 QApplication 서브클래스의 구현은 예를 들어 애플리케이션의 Dock 아이콘에 드래그한 파일을 열기 위해 QFileOpenEvent를 처리하는 방법을 보여줍니다.
#include <QApplication> #include <QDebug> #include <QFile> #include <QFileOpenEvent> #include <QPushButton> class MyApplication : public QApplication { public: MyApplication(int &argc, char **argv) : QApplication(argc, argv) { } bool event(QEvent *event) override { if (event->type() == QEvent::FileOpen) { QFileOpenEvent *openEvent = static_cast<QFileOpenEvent *>(event); const QUrl url = openEvent->url(); if (url.isLocalFile()) { QFile localFile(url.toLocalFile()); // read from local file } else if (url.isValid()) { // process according to the URL's schema } else { // parse openEvent->file() } } return QApplication::event(event); } };
QFileOpenEvent::file() 이 QFile 을 사용하여 열 수 있는 로컬 파일의 이름이라고 보장할 수 없다는 점에 유의하세요. 문자열의 내용은 소스 애플리케이션에 따라 다릅니다.
© 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.