Qt Qml의 변경 사항
Qt 6는 프레임워크를 보다 효율적이고 사용하기 쉽게 만들기 위한 의식적인 노력의 결과물입니다.
각 릴리스에서 모든 공개 API에 대한 바이너리 및 소스 호환성을 유지하려고 노력합니다. 하지만 Qt를 더 나은 프레임워크로 만들기 위해 몇 가지 변경이 불가피했습니다.
이 항목에서는 Qt Qml의 이러한 변경 사항을 요약하고 이를 처리하기 위한 지침을 제공합니다.
QML 언어
URL 확인
Qt 5에서는 특히 URL 프로퍼티에 할당된 상대 URL이 일관성이 없기는 하지만 직접 해결되는 경우가 많았습니다. Qt 6에서는 더 이상 그렇지 않습니다.
"/home/qml/example.qml" 아래에 QML 파일이 저장되어 있고 "example.qml"이 포함된 경우
property url imageFolder: "./images"
이 포함되어 있다면, url 속성은 "/home/qml/images" URL을 저장합니다. 이로 인해 QML에서 이러한 방식으로 상대 URL을 사용할 수 없게 되었기 때문에 Qt 6에서는 URL이 상대적인 상태로 유지되며, 필요한 경우(예: 이미지 컴포넌트의 소스로 사용되는 경우)에만 확인됩니다. 이전 동작에 의존하는 경우 다음을 사용할 수 있습니다. Qt.resolvedUrl
예를 들어 다음과 같은 코드가 있는 경우
property url imageFolder: "./images"
와 같은 코드가 있다면 다음과 같이 다시 작성할 수 있습니다.
property url imageFolder: Qt.resolvedUrl("./images")
Qt.resolvedUrl은 Qt 5와 6 모두에서 사용할 수 있습니다.
변형 프로퍼티
variant
프로퍼티는 Qt 5부터 더 이상 사용되지 않는 것으로 표시되었지만 이제 var
프로퍼티와 똑같은 방식으로 취급됩니다. 변형 프로퍼티에 할당할 때 트리거되는 암시적 문자열 변환에 의존하는 코드는 올바른 유형의 객체를 명시적으로 생성하도록 업데이트해야 합니다.
예를 들어 다음과 같은 코드가 있는 경우
property variant myColor: "red"
와 같은 코드가 있는 경우 다음과 같이 다시 작성할 수 있습니다.
property variant myColor: Qt.color("red")
다음과 같이 구문 분석할 수 있는 문자열에 대해 암시적 변환이 수행되었습니다.
- color (대신 Qt.color 사용),
- date (대신 Date 객체 사용),
- rect (대신 Qt.rect 사용) 및
- size (대신 Qt.size 사용)
variant
는 여전히 Qt 6에서 사용되지 않는 키워드로 남아 있지만, 새 코드에서는 var
프로퍼티를 대신 사용할 것을 강력히 권장합니다.
참고: 속성 유형이 변경되지 않는 것으로 알려진 경우 var
속성 대신 구체적인 유형의 속성을 사용하십시오.
참고: 이러한 변환은 엔진에 등록된 클래스의 QVariant
프로퍼티에도 적용되었습니다. variant
프로퍼티와 마찬가지로 암시적 문자열 변환에 의존하는 코드는 Qt 객체의 해당 함수를 사용해야 합니다.
소스 호환되지 않는 API 변경 사항
변경된 API
QQmlListProperty
의 CountFunction
및 AtFunction
은 Qt 컨테이너의 해당 변경 사항에 따라 int
대신 qsizetype
을 사용하도록 변경되었습니다.
예를 들어 다음과 같은 코드가 있는 경우
int myCountFunction(QQmlListProperty<MyType> *); MyType *myAtFunction(QQmlListProperty<MyType> *, int); QQmlListProperty<MyType> myReadOnlyList(containingObject, container, &myCountFunction, &myAtFunction);
와 같은 코드가 있다면 다음과 같이 다시 작성할 수 있습니다.
qsizetype myCountFunction(QQmlListProperty<MyType> *); MyType *myAtFunction(QQmlListProperty<MyType> *, qsizetype); QQmlListProperty<MyType> myReadOnlyList(containingObject, container, &myCountFunction, &myAtFunction);
Qt 5와 Qt 6을 모두 지원해야 하는 코드는 Qt 5에서는 int
, Qt 6에서는 qsizetype
인 typedef를 사용하거나 이미 그러한 유형 별칭인 QList::size_type
을 사용할 수 있습니다.
제거된 API
더 이상 사용되지 않는 다양한 함수가 제거되었습니다.
- 참조를 받는 QQmlListProperty 생성자가 제거되었습니다.
예를 들어 다음과 같은 코드가 있는 경우
QQmlListProperty<QObject>(owner, owner->objectList);
와 같은 코드가 있는 경우 다음과 같이 다시 작성할 수 있습니다.
QQmlListProperty<QObject>(owner, &owner->objectList);
qmlDebug
,qmlInfo
,qmlWarning
,qmlContext
,qmlEngine
함수는 글로벌 네임스페이스(또는 네임스페이스 빌드에서는 Qt 네임스페이스)와QtQml
네임스페이스에 모두 존재했습니다. 이제 이러한 함수는 전역 네임스페이스에만 존재합니다.예를 들어 다음과 같은 코드가 있는 경우
QQmlEngine *engine = QtQml::qmlEngine(qmlObject);
와 같은 코드가 있다면 다음과 같이 다시 작성할 수 있습니다.
QQmlEngine *engine = qmlEngine(qmlObject);
- 인수를 받지 않는
qmlRegisterType
오버로드가 제거되었습니다. 대신qmlRegisterAnonymousType
을 사용하거나QML_ANONYMOUS
을 사용하여 선언적 유형 등록으로 전환하세요.예를 들어 다음과 같은 코드가 있는 경우
class AnonymousType : public QObject { // ... }; qmlRegisterType<AnonymousType>();
와 같은 코드가 있는 경우 다음과 같이 다시 작성할 수 있습니다.
class AnonymousType : public QObject { // ... }; qmlRegisterAnonymousType<AnonymousType>("MyModule", 1);
또는
class AnonymousType : public QObject { QML_ANONYMOUS // ... };
- 버전 인수를 받지 않는
qmlRegisterExtendedType
및qmlRegisterInterface
의 오버로드가 제거되었습니다. 버전을 제공하는 오버로드를 사용하거나 QML_EXTENDED 및 QML_INTERFACE 을 사용하여 선언적 유형 등록으로 전환합니다.예를 들어 다음과 같은 코드가 있는 경우
struct GreetInterface { virtual ~GreetInterface(); virtual void greet(); }; Q_DECLARE_INTERFACE(GreetInterface, "org.hi.GreetInterface") qmlRegisterInterface<GreetInterface>("Greeter");
와 같은 코드가 있는 경우 다음과 같이 다시 작성할 수 있습니다.
struct GreetInterface { virtual ~GreetInterface(); virtual void greet(); }; Q_DECLARE_INTERFACE(GreetInterface, "org.hi.GreetInterface") qmlRegisterInterface<GreetInterface>("Greeter", 1);
또는
struct GreetInterface { QML_INTERFACE(Greeter) virtual ~GreetInterface(); virtual void greet(); }; Q_DECLARE_INTERFACE(GreetInterface, "org.hi.GreetInterface")
참고: 새 코드에서는 선언적 유형 등록을 선호해야 합니다.
QJSValue::engine
함수가 제거되었습니다. 엔진에 대한 액세스가 필요한 경우 엔진에 대한 참조를 대신 저장해야 합니다.qmlAttachedPropertiesObjectById
및qmlAttachedPropertiesObject(int *, const QObject *, const QMetaObject *, bool)
함수가 제거되었습니다. 대신qmlAttachedPropertiesObject
의qmlAttachedPropertiesObject(QObject *, QQmlAttachedPropertiesFunc, bool)
오버로드를 사용하십시오.QJSEngine::installTranslatorFunctions
QJSEngine::installExtensions
을 대체할 수 있습니다.예를 들어 다음과 같은 코드가 있는 경우
QJSEngine engine; engine.installTranslatorFunctions();
와 같은 코드가 있는 경우 다음과 같이 다시 작성할 수 있습니다.
© 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.