Qt Protobuf 뮤터블 게터

생성된 Qt Protobuf 메시지는 변경 가능한 게터를 사용하여 메시지 유형의 필드에 액세스할 수 있습니다. 게터는 mut 접두사를 가지며 필드에 대한 참조가 아닌 참조를 반환합니다.

message Point {
    double x = 1;
    double y = 2;
}

message Line {
    Point start = 1;
    Point end = 2;
}

위의 .proto 스키마는 Line 메시지에 대해 다음 코드를 생성합니다:

class Line : public QProtobufMessage
{
    const Point &start() const &;
    Point &mutStart() &;
    ...

    const Point &end() const &;
    Point &mutEnd() &;
    ...
}

startend 필드의 경우, qtprotobufgen 생성기는 mutStartmutEnd 와 같은 가변 가능한 추가 게터를 생성합니다. 이러한 게터를 사용하여 중간 메시지를 만들지 않고 필드를 직접 수정할 수 있습니다:

선 line;// 선 시작점을 (5.0, 5.0)으로 설정line.mutStart().setX(5.0); line.mutStart().setY(5.0);// 선 끝점을 (10.0, 20.0)으로 설정line.mutEnd().setX(10.0); line.mutEnd().setY(20.0);// 선 데이터를 표시합니다.qDebug().nospace() << "start: (" << line.start().x() << "," << line.start().y() << ") "
   "end: ("<< line.end().x()<< ","<< line.end().y()<< ")";

가변 게터를 호출하면 필요한 필드 할당이 수행되고 기본 데이터를 직접 수정할 수 있습니다.

경고: 변경 가능한 게터는 필드 이름에 mut 접두사를 추가합니다. 메시지에 fieldmutField 이라는 이름의 필드가 포함된 경우 명명 충돌이 발생합니다. 이 시나리오는 현재 지원되지 않으며 생성기 오류가 발생합니다.

© 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.