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 can be created using a factory method of the Ros singleton.

1/* ... */
2ApplicationWindow {
3  property var intPublisher: Ros.advertise("std_msgs/Int32", "/intval", 10, false)
4  /* ... */

In order, the arguments are the type, the topic, the queueSize and whether or not the topic isLatched.

To publish a message using our Publisher, we can simply use the intPublisher variable.

1SpinBox {
2  id: numberInput
5Button {
6  onClicked: {
7    intPublisher.publish({ data: numberInput.value })
8  }

where we pass an object with a data field containing the (integer) number of the SpinBox. This is according to the std_msgs/Int32 message definition.



class qml_ros_plugin::Publisher : public QObject

Public Functions

Publisher(NodeHandle::Ptr nh, QString type, QString topic, uint32_t queue_size, bool latch)

The type of the published messages, e.g., geometry_msgs/Pose.

The topic this Publisher publishes messages on. This property is only valid if the publisher is already advertised! Whether or not this Publisher is latched. A latched Publisher always sends the last message to new subscribers. The queue size of this Publisher. This is the maximum number of messages that are queued for delivery to subscribers at a time. Whether or not this publisher has advertised its existence on its topic. Reasons for not being advertised include ROS not being initialized yet.

unsigned int getNumSubscribers()

The number of subscribers currently connected to this Publisher.

bool publish(const QVariantMap &msg)

Sends a message to subscribers currently connected to this Publisher.


msg – The message that is published.


True if the message was sent successfully, false otherwise.


void advertised()

Fired once this Publisher was advertised. This is either done at construction or immediately after ROS is initialized. Since this is only fired once, you should check if the Publisher is already advertised using the isAdvertised property.

void connected()

Fired whenever a new subscriber connects to this Publisher.

void disconnected()

Fired whenever a subscriber disconnects from this Publisher.