PublisherBase QML Type
Abstract base for all generated ROS 2 publisher types. More...
Properties
- autoPublish : bool
- publishInterval : int
- subscriberCount : int
Methods
- void publish()
Detailed Description
PublisherBase is not creatable directly. Use a generated publisher type such as TimePublisher from QtRos2.BuiltinInterfaces.
Automatic publishing
Generated multi-field publishers (e.g. TwistPublisher with its linear and angular properties) store the most recently assigned field values and can publish them automatically. Two orthogonal properties control when a publish happens:
- autoPublish — publish whenever any field property changes (responsiveness).
- publishInterval — publish at least this often, in milliseconds (liveness / watchdog).
The two combine into four behaviors:
| autoPublish | publishInterval | behavior |
|---|---|---|
false | 0 | Manual only. Call publish() (or a typed publish(msg) overload) explicitly. Field property writes update the stored message silently. |
true | 0 | Publish on change (default). Each field property write schedules a publish at the end of the current event-loop iteration; multiple writes in one iteration coalesce into one publish. |
false | > 0 | Rate-driven heartbeat. The timer publishes the stored message every publishInterval ms; intervening property writes silently accumulate. Useful for sending a stream of state at a fixed rate (e.g. cmd_vel for a robot base with a watchdog timeout). |
true | > 0 | Publish on change and at least every publishInterval ms. Property writes publish immediately (coalesced) and also reset the heartbeat timer, so the timer only fires when the publisher has been quiet for publishInterval ms. Useful for state publishers that want low latency on changes plus a periodic heartbeat for consumers that watch for liveness. |
Event-loop coalescing
When autoPublish is true, assigning a field property does not publish immediately. Instead it sets an internal pending flag and, on the first such assignment per event-loop iteration, posts a queued metacall (Qt::QueuedConnection) to publish(). Every subsequent property assignment in the same iteration finds the flag already set and does nothing extra. When the event loop next spins, publish() runs once with all the accumulated changes in place.
The batching boundary is therefore one trip through the event loop, not one JavaScript expression. A single QTouchEvent that drives bindings to four separate field properties produces one publish. Updates separated by an awaited signal, a QTimer::singleShot(0), or a queued cross-thread signal land in different iterations and publish independently.
Property Documentation
autoPublish : bool
If true (the default), assigning any field property of a publisher schedules a publish at the end of the current event-loop iteration. Multiple assignments per iteration coalesce into one publish. If false, field property writes update the stored message silently and publish() must be called explicitly.
Has no effect on empty publisher types, which have no stored state.
publishInterval : int
If greater than zero, publish the stored message every publishInterval milliseconds. Combined with autoPublish, the timer is reset on each change-driven publish, so the heartbeat fires only when the publisher has been quiet for the full interval. Defaults to 0 (no timer).
Has no effect on empty publisher types, which have no stored state.
subscriberCount : int
The number of subscribers currently listening on topic. Updated periodically by a background health-check timer.
Method Documentation
void publish()
Publishes the stored message state. For empty publisher types this is a no-op. Single-field publishers also offer a typed publish(value) overload that sends a value immediately without touching the stored property.
Calling this clears any pending coalesced publish and, when publishInterval is greater than zero, restarts the heartbeat timer so the next periodic publish is publishInterval ms from now.
© 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.