Qt Protobuf 변경 가능한 게터
생성된 Qt Protobuf 메시지를 사용하면 가변형 게터를 통해 메시지 유형의 필드에 접근할 수 있습니다. 게터는 mut 접두사를 가지며, 필드에 대한 비const 참조를 반환합니다.
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() &;
...
}start 및 end 필드의 경우, qtprotobufgen 생성기는 mutStart 및 mutEnd 와 같은 추가적인 가변형 게터(getter)를 생성합니다. 중간 메시지를 생성하지 않고 필드를 직접 수정하려면 이 게터들을 사용하십시오:
Line 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);
// Line 데이터 표시
qDebug().nospace() << "start: (" << line.start().x() << "," << line.start().y() << ") "
"end: (" << line.end().x() << "," << line.end().y() << ")";변경 가능한 게터 메서드를 호출하면 필요한 필드 할당이 수행되며, 기본 데이터를 직접 수정할 수 있습니다.
경고: 가변 게터는 필드 이름 앞에 mut 접두사를 추가합니다. 메시지에 field 및 mutField 라는 이름의 필드가 포함되어 있으면 이름 충돌이 발생합니다. 이 시나리오는 현재 지원되지 않으며, 제너레이터 오류가 발생합니다.
© 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.