조회 수 12411 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

Qt Quick 응용프로그램에서는 일반적으로 QML "프론트엔드"와 함께 C++ 백엔드를 구현하여 개발한다. C++ 백엔드는 QML엔진의 rootContext() 를 통해 QML 계층에 노출되는 QObject 의 파생 클래스이다.

main.cpp

// Create instance of MyItem.
MyItem myitem;
engine.rootContext()->setContextProperty("myItem", &myitem);

main.qml

SomeItem {
    property string name: myItem.name // myItem의 속성을 바인딩.
}

애플리케이션을 종료할 때 흔히 바인딩오류를 발견할 수 있다. 애플리케이션이 완전히 종료하기 전에 백엔드가 이미 파괴되었기 때문에 QML 엔진에서 바인딩 오류가 발생한다는 것이다. 그 이유는 QML 엔진이 백엔드가 있을 것으로 기대하면서 백엔드보다 오래 지속되기 때문이다.

다음은 출력에서 가져온 에러 메세지이다.

qrc:/main.qml:13: TypeError: Cannot read property 'name' of null

이에 대한 두 가지 해결 방법이 있다. 한 가지 방법은 백엔드가 QML 엔진보다 먼저 생성되어 백엔드 객체가 마지막으로, 또는 적어도 엔진 이후에 자체적으로 소멸되도록 하는 것이다.

// QML 엔진 이전에 구축된 MyItem.
MyItem myitem;
QQmlApplicationEngine engine;

다른 방법은 힙에 백엔드를 만들고 다음과 같이 엔진을 부모로 설정하는 것이다. 이것은 엔진이 파괴될 때 백엔드도 파괴된다는 것을 의미한다.

QQmlApplicationEngine engine;

// Create instance of MyItem.
auto myitem = new MyItem(&engine);

첫 번째 방법이 더 간단하고 스택에서 직접 객체를 생성한다고 생각한다. 다만 순서를 조정하는게 간단하면서도 실수하여 버그가 생기기 쉽다. 두 번째 옵션은 실수로 순서를 변경할 수 없다는 점에서 더 강력하다(엔진이 존재하지 않는 한 백엔드를 선언할 수 없음).

애플리케이션이 이미 종료되고 있기 때문에 오류 자체는 무해하지만 그럼에도 불구하고 존재해서는 안 되는 오류이다.


  1. No Image notice

    Qt프로그래밍(QtQuick) Beginner를 위한 글 읽는 순서

    Date2019.01.05 CategoryQML and Qt Quick By운영자 Views451497
    read more
  2. No Image

    clazy 로 13개의 시그널, 슬롯 오류 해결

    Date2022.08.23 CategoryGeneral and Desktop Bymakersweb Views9615
    Read More
  3. No Image

    Qt 스마트 포인터 (QSharedPointer, QScopedPointer, QPointer)

    Date2022.08.18 CategoryC++ Class Bymakersweb Views6752
    Read More
  4. Qt 6.4에 추가될 Qt Quick 3D Physics

    Date2022.08.07 CategoryQt 6 Bymakersweb Views7176
    Read More
  5. No Image

    HTTPS URL을 연결할 때 SslHandshakeFailedError 오류

    Date2022.07.31 CategoryC++ Class Bymakersweb Views8096
    Read More
  6. No Image

    단일 인스턴스 Qt 응용 프로그램(Single-instance Application)

    Date2022.06.23 CategoryGeneral and Desktop Bymakersweb Views6881
    Read More
  7. Qt로 작성된 iOS 앱에서 시리얼 통신

    Date2022.04.30 CategoryMobile and Embedded Bymakersweb Views13939
    Read More
  8. No Image

    VirtualKeyboard 스타일 커스터 마이징

    Date2022.03.13 CategoryGeneral and Desktop Bymakersweb Views7547
    Read More
  9. No Image

    성능 고려 및 제안 사항

    Date2022.03.07 Bymakersweb Views5549
    Read More
  10. No Image

    Binding 타입으로 객체 속성 간 묶기

    Date2022.03.04 CategoryQML and Qt Quick Bymakersweb Views8462
    Read More
  11. No Image

    Qt Bluetooth Low Energy 개요

    Date2022.02.13 CategoryMobile and Embedded Bymakersweb Views8753
    Read More
  12. Qt Android 앱에 AdMob 배너달기

    Date2021.12.04 CategoryMobile and Embedded Bymakersweb Views4816
    Read More
  13. No Image

    Qt 6의 C++ 프로퍼티 바인딩 예제

    Date2021.11.01 CategoryQt 6 Bymakersweb Views7637
    Read More
  14. QML에서 앵커(anchors)로 위치 지정

    Date2021.10.05 CategoryQML and Qt Quick Bymakersweb Views11013
    Read More
  15. No Image

    안드로이드용 Qt 6.2

    Date2021.10.02 CategoryQt 6 Bymakersweb Views14744
    Read More
  16. Qt 응용프로그램에서 PDF 문서 렌더링

    Date2021.09.23 CategoryGeneral and Desktop Bymakersweb Views6574
    Read More
  17. QML에서 Websocket 서버와 통신

    Date2021.09.18 CategoryQML and Qt Quick Bymakersweb Views6113
    Read More
  18. No Image

    QML 코딩 규칙

    Date2021.09.05 CategoryQML and Qt Quick Bymakersweb Views10268
    Read More
  19. QML 에서 QR코드 생성

    Date2021.08.20 CategoryQML and Qt Quick Bymakersweb Views6124
    Read More
  20. No Image

    앱을 종료할 때 QML 바인딩 오류를 피하는 방법

    Date2021.08.08 CategoryQML and Qt Quick Bymakersweb Views12411
    Read More
  21. Qt 응용프로그램에서 Lottie Animation사용

    Date2021.05.30 CategoryQML and Qt Quick Bymakersweb Views6777
    Read More
Board Pagination Prev 1 2 3 4 5 9 Next
/ 9