On this page

Simple Subscriber

Subscribing to a geometry_msgs/PoseStamped message and binding its fields into the UI.

Simple Subscriber is the receiving counterpart to Simple Publisher. It subscribes to a geometry_msgs/PoseStamped topic with a single PoseStampedSubscriber and displays the incoming pose — position, orientation (as a quaternion and as Euler angles), timestamp, and frame — using ordinary QML property bindings.

The Simple Subscriber window showing the latest received pose, its frame and timestamp, and the orientation as both a quaternion and Euler angles.

Running the example

  1. Source your ROS 2 environment and launch Qt Creator from that shell.
  2. Open examples/simple_subscriber/CMakeLists.txt in Qt Creator, then build and run.
  3. Run the Simple Publisher example (or any node publishing geometry_msgs/PoseStamped on /simple_publisher_pose) so there is something to receive.

Declaring a subscriber

As with a publisher, a subscriber is a child of a Node. It can be given an explicit node and its topic can be edited live:

import QtRos2.Core
import QtRos2.GeometryMsgs as Geom

Node {
    id: rosNode
    nodeName: "simple_subscriber_node"

    Geom.PoseStampedSubscriber {
        id: poseSubscriber
        node: rosNode
        topic: topicField.text

        onMessageReceived: (msg) => ++root.messageCount
    }
}

There are two ways to react to incoming data, and this example uses both:

  • The onMessageReceived handler fires once per message. Here it is used only to count messages; it is also the right place for imperative logic that must run exactly once per message.
  • Property bindings onto the subscriber's message (and its convenience accessors) update automatically whenever a new message arrives — no handler required.

Reactive bindings and convenience accessors

The subscriber exposes the last message as message, and a stamped subscriber also surfaces shortcut accessors so common paths read cleanly. For a PoseStampedSubscriber, poseSubscriber.pose and poseSubscriber.header are equivalent to poseSubscriber.message.pose and poseSubscriber.message.header:

// These value-type properties re-evaluate every time a message arrives.
property Geom.point position: poseSubscriber.pose.position
property Geom.quaternion orientation: poseSubscriber.pose.orientation

Label { text: `x=${root.position.x}  y=${root.position.y}  z=${root.position.z}` }
Label { text: `frame: ${poseSubscriber.message.header.frameId}` }
Euler angles for free

A geometry_msgs/Quaternion value type also exposes its orientation as Euler angles, so you do not have to convert by hand. rpyDegrees gives roll/pitch/yaw in degrees (there is a matching radians accessor):

Label {
    text: `roll=${orientation.rpyDegrees.x}°  ` +
          `pitch=${orientation.rpyDegrees.y}°  ` +
          `yaw=${orientation.rpyDegrees.z}°`
}

Connection status

Alongside rosNode.initialized, a subscriber reports whether a publisher is present on its topic through the connected property. The example uses it to show "Publisher available" versus "Waiting for publisher", which makes it obvious whether the absence of data is a connection problem or simply that nothing has been published yet.

Files:

Images:

See also Simple Publisher and Qt ROS2 geometry_msgs QML Types.

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