Publishers¶
A Publisher is used to publish messages on a given topic for delivery to subscribers.
Simple Example¶
Contrary to Subscribers, a Publisher can not be instantiated but is created using a factory method of the Ros2 singleton.
1/* ... */
2ApplicationWindow {
3 property var intPublisher: Ros2.advertise("/intval", "example_interfaces/msg/Int32", 10)
4 /* ... */
5}
In order, the arguments are the topic
, the type
and the queueSize
(defaults to 1).
Additional QoS options are currently not supported.
To publish a message using our Publisher, we can simply use the intPublisher
variable defined earlier.
1SpinBox {
2 id: numberInput
3}
4
5Button {
6 onClicked: {
7 intPublisher.publish({ data: numberInput.value })
8 }
9}
where we pass an object with a data field containing the (integer) number of the SpinBox
.
This is according to the example_interfaces/msg/Int32
message definition.
API¶
Publisher¶
-
class Publisher : public QObjectRos2¶
Public Functions
Signals
Properties
- QString type
The type of the published messages, e.g., geometry_msgs/Pose. (readonly)
- QString topic
The topic this Publisher publishes messages on. This property is only valid if the publisher is already advertised! (readonly)
- quint32 queueSize
The queue size of this Publisher. This is the maximum number of messages that are queued for delivery to subscribers at a time. (readonly)
- bool isAdvertised
Whether or not this publisher has advertised its existence on its topic. Reasons for not being advertised include ROS not being initialized yet. (readonly)