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는 이벤트 클래스의 일부입니다.
공개 함수
보호된 함수
| QFileOpenEvent(QFileOpenEvent &&) | |
| QFileOpenEvent & | operator=(QFileOpenEvent &&) |
| QFileOpenEvent & | operator=(const QFileOpenEvent &other) |
상세 설명
운영 체제가 파일 또는 URL을 열도록 요청하면 파일 열기 이벤트가 ` QApplication::instance()`로 전송됩니다. 이는 플랫폼에 따라 다양한 사용자 동작으로 인해 발생할 수 있는 상위 수준의 이벤트입니다. 예를 들어, macOS에서는 Finder에서 파일을 더블 클릭하거나 파일을 애플리케이션의 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 를 사용하여 열 수 있는 로컬 파일의 이름이라고 보장되지 않는다는 점에 유의하십시오. 이 문자열의 내용은 소스 애플리케이션에 따라 다릅니다.
멤버 함수 설명서
[protected delete] QFileOpenEvent::QFileOpenEvent(QFileOpenEvent &&)
QFileOpenEvent 의 인스턴스를 move-construct로 생성합니다. 이 함수는 삭제되었습니다.
QString QFileOpenEvent::file() const
애플리케이션이 열어야 할 파일의 이름을 반환합니다.
이 경로가 반드시 로컬 파일의 경로일 것이라고 보장되지는 않습니다.
QUrl QFileOpenEvent::url() const
애플리케이션이 열어야 할 URL을 반환합니다.
[protected delete] QFileOpenEvent &QFileOpenEvent::operator=(QFileOpenEvent &&)
other 를 이 QFileOpenEvent 인스턴스에 이동-할당합니다. 이 함수는 삭제됩니다.
[noexcept protected default] QFileOpenEvent &QFileOpenEvent::operator=(const QFileOpenEvent &other)
other 를 이 QFileOpenEvent 인스턴스에 복사-할당합니다.
© 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.