QTemporaryDir Class
QTemporaryDir 클래스는 임시로 사용할 고유 디렉터리를 생성합니다. 더 보기...
헤더: | #include <QTemporaryDir> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
qmake: | QT += core |
- 상속된 멤버를 포함한 모든 멤버 목록
- QTemporaryDir은 입력/출력 및 네트워킹의 일부입니다.
참고: 이 클래스의 모든 함수는 재진입합니다.
공용 함수
QTemporaryDir() | |
QTemporaryDir(const QString &templatePath) | |
(since 6.4) | QTemporaryDir(QTemporaryDir &&other) |
~QTemporaryDir() | |
bool | autoRemove() const |
QString | errorString() const |
QString | filePath(const QString &fileName) const |
bool | isValid() const |
QString | path() const |
bool | remove() |
void | setAutoRemove(bool b) |
(since 6.4) void | swap(QTemporaryDir &other) |
(since 6.4) QTemporaryDir & | operator=(QTemporaryDir &&other) |
상세 설명
QTemporaryDir은 고유한 임시 디렉터리를 안전하게 생성하는 데 사용됩니다. 디렉터리 자체는 생성자에 의해 생성됩니다. 임시 디렉터리의 이름은 고유하도록 보장되며(즉, 기존 디렉터리를 덮어쓰지 않도록 보장됨), 디렉터리는 이후 QTemporaryDir 객체가 소멸될 때 제거됩니다. 디렉터리 이름은 자동 생성되거나 템플릿을 기반으로 생성되며, 이 템플릿은 QTemporaryDir의 생성자에게 전달됩니다.
예시:
// Within a function/method... QTemporaryDir dir; if (dir.isValid()) { // dir.path() returns the unique directory path } // The QTemporaryDir destructor removes the temporary directory // as it goes out of scope.
isValid()를 사용하여 임시 디렉터리를 만들 수 있는지 테스트하는 것이 매우 중요합니다. exists ()를 사용하지 마세요. 기본으로 구성된 QDir 은 현재 존재하는 디렉터리를 나타내므로 사용하지 마세요.
임시 디렉터리의 경로는 path()를 호출하여 찾을 수 있습니다.
임시 디렉터리에는 이름에 정적인 부분과 고유한 것으로 계산되는 부분이 있습니다. 기본 경로는 QCoreApplication::applicationName()(그렇지 않으면 qt_temp
)에서 결정되며 QDir::tempPath()에서 반환된 임시 경로에 배치됩니다. 직접 경로를 지정하는 경우 상대 경로는 기본적으로 임시 디렉터리에 배치되지 않고 현재 작업 디렉터리에 상대 경로가 됩니다. 모든 경우에 경로를 고유하게 만들기 위해 임의의 문자열이 경로에 추가됩니다.
QDir::tempPath(), QDir, QTemporaryFile 를참조하세요 .
멤버 함수 문서
QTemporaryDir::QTemporaryDir()
QCoreApplication::applicationName()에서 반환한 애플리케이션 이름을 템플릿으로 사용하여 QTemporaryDir을 구축합니다(그렇지 않으면 qt_temp
). 디렉터리는 시스템의 임시 디렉터리 QDir::tempPath()에 저장됩니다.
QDir::tempPath()도 참조하세요 .
[explicit]
QTemporaryDir::QTemporaryDir(const QString &templatePath)
템플릿이 templatePath 인 QTemporaryDir을 생성합니다.
templatePath 이 상대 경로인 경우 경로는 현재 작업 디렉터리에 상대 경로가 됩니다. 시스템의 임시 디렉터리를 사용하려는 경우 QDir::tempPath()를 사용하여 templatePath 을 구성할 수 있습니다.
templatePath 가 XXXXXX 로 끝나면 디렉토리 이름의 동적 부분으로 사용되며, 그렇지 않으면 추가됩니다. QTemporaryFile 과 달리 템플릿 문자열 중간에 있는 XXXXXX 는 지원되지 않습니다.
QDir::tempPath()도 참조하세요 .
[noexcept, since 6.4]
QTemporaryDir::QTemporaryDir(QTemporaryDir &&other)
Move는 other 에서 새 QTemporaryDir을 생성합니다.
참고: 이동한 객체 other 는 부분적으로 형성된 상태로 배치되며, 유효한 연산은 파괴와 새 값 할당뿐입니다.
이 함수는 Qt 6.4에 도입되었습니다.
[noexcept]
QTemporaryDir::~QTemporaryDir()
임시 디렉터리 객체를 삭제합니다. 자동 제거 모드가 설정된 경우 모든 콘텐츠를 포함한 디렉터리를 자동으로 삭제합니다.
autoRemove()도 참조하세요 .
bool QTemporaryDir::autoRemove() const
QTemporaryDir 이 자동 제거 모드인 경우 true
을 반환합니다. 자동 제거 모드는 삭제 시 디스크에서 디렉터리를 자동으로 삭제합니다. 이렇게 하면 스택에 QTemporaryDir 객체를 만들고, 파일로 채우고, 파일로 무언가를 하고, 마지막으로 함수 반환 시 자동으로 정리하는 작업이 매우 쉬워집니다.
자동 제거는 기본적으로 켜져 있습니다.
setAutoRemove() 및 remove()도 참조하세요 .
QString QTemporaryDir::errorString() const
isValid()가 false
을 반환하면 이 함수는 임시 디렉터리 생성에 실패한 이유를 설명하는 오류 문자열을 반환합니다. 그렇지 않으면 이 함수는 빈 문자열을 반환합니다.
QString QTemporaryDir::filePath(const QString &fileName) const
임시 디렉터리에 있는 파일의 경로 이름을 반환합니다. 파일이 디렉터리에 실제로 존재하는지 확인하지 않습니다. fileName 에서 중복된 여러 구분 기호 또는 "." 및 "." 디렉토리는 제거되지 않습니다( QDir::cleanPath() 참조). 절대 경로는 허용되지 않습니다.
QTemporaryDir 이 상대 경로로 작성되었는지 절대 경로로 작성되었는지에 따라 반환되는 경로는 상대 경로 또는 절대 경로가 됩니다.
bool QTemporaryDir::isValid() const
QTemporaryDir 이 성공적으로 생성된 경우 true
을 반환합니다.
QString QTemporaryDir::path() const
임시 디렉터리 경로를 반환합니다. QTemporaryDir 을 만들 수 없는 경우 비어 있습니다.
반환되는 경로는 QTemporaryDir 이 상대 경로로 작성되었는지 절대 경로로 작성되었는지에 따라 상대 경로 또는 절대 경로가 됩니다.
bool QTemporaryDir::remove()
모든 콘텐츠를 포함하여 임시 디렉터리를 제거합니다.
제거에 성공하면 true
을 반환합니다.
void QTemporaryDir::setAutoRemove(bool b)
b 이 참이면 QTemporaryDir 을 자동 제거 모드로 설정합니다.
자동 제거는 기본적으로 켜져 있습니다.
autoRemove() 및 remove()도 참조하세요 .
[noexcept, since 6.4]
void QTemporaryDir::swap(QTemporaryDir &other)
이 임시 디렉토리를 other 로 바꿉니다. 이 작업은 매우 빠르며 실패하지 않습니다.
이 함수는 Qt 6.4에 도입되었습니다.
[noexcept, since 6.4]
QTemporaryDir &QTemporaryDir::operator=(QTemporaryDir &&other)
이동 - other 을 이 QTemporaryDir 인스턴스에 할당합니다.
참고: 이동된 객체 other 는 부분적으로 형성된 상태로 배치되며, 유효한 작업은 소멸과 새 값 할당뿐입니다.
이 함수는 Qt 6.4에 도입되었습니다.
© 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.