On this page

PublisherBase QML Type

Abstract base for all generated ROS 2 publisher types. More...

Import Statement: import QtRos2.Core
Inherits:

Entity

Inherited By:
164 types

AccelPublisher, AccelStampedPublisher, AccelWithCovariancePublisher, AccelWithCovarianceStampedPublisher, ActionPublisher, BatteryStatePublisher, BoolPublisher, ByteMultiArrayPublisher, BytePublisher, CameraInfoPublisher, ChannelFloat32Publisher, CharPublisher, ClockPublisher, ColorRGBAPublisher, CompressedImagePublisher, DiagnosticArrayPublisher, DiagnosticStatusPublisher, DisparityImagePublisher, DurationPublisher, EmptyPublisher, FieldPublisher, FieldTypePublisher, Float32MultiArrayPublisher, Float32Publisher, Float64MultiArrayPublisher, Float64Publisher, FloatingPointRangePublisher, FluidPressurePublisher, GoalInfoPublisher, GoalsPublisher, GoalStatusArrayPublisher, GoalStatusPublisher, GraphPublisher, GridCellsPublisher, HeaderPublisher, IlluminancePublisher, ImageMarkerPublisher, ImagePublisher, ImuPublisher, IndividualTypeDescriptionPublisher, InertiaPublisher, InertiaStampedPublisher, Int16MultiArrayPublisher, Int16Publisher, Int32MultiArrayPublisher, Int32Publisher, Int64MultiArrayPublisher, Int64Publisher, Int8MultiArrayPublisher, Int8Publisher, IntegerRangePublisher, InteractiveMarkerControlPublisher, InteractiveMarkerFeedbackPublisher, InteractiveMarkerInitPublisher, InteractiveMarkerPosePublisher, InteractiveMarkerPublisher, InteractiveMarkerUpdatePublisher, InterfaceTypePublisher, JointStatePublisher, JointTrajectoryPointPublisher, JointTrajectoryPublisher, JoyFeedbackArrayPublisher, JoyFeedbackPublisher, JoyPublisher, LaserEchoPublisher, LaserScanPublisher, ListParametersResultPublisher, LoggerLevelPublisher, LogPublisher, MagneticFieldPublisher, MapMetaDataPublisher, MarkerArrayPublisher, MarkerPublisher, MenuEntryPublisher, MeshFilePublisher, MeshPublisher, MeshTrianglePublisher, MetricsMessagePublisher, MultiArrayDimensionPublisher, MultiArrayLayoutPublisher, MultiDOFJointStatePublisher, MultiDOFJointTrajectoryPointPublisher, MultiDOFJointTrajectoryPublisher, MultiEchoLaserScanPublisher, NavSatFixPublisher, NavSatStatusPublisher, NodePublisher, OccupancyGridPublisher, OdometryPublisher, ParameterDescriptorPublisher, ParameterEventDescriptorsPublisher, ParameterEventPublisher, ParameterPublisher, ParameterTypePublisher, ParameterValuePublisher, PathPublisher, PlanePublisher, PointCloud2Publisher, PointCloudPublisher, PointFieldPublisher, PointPublisher, PointStampedPublisher, PolygonInstancePublisher, PolygonInstanceStampedPublisher, PolygonPublisher, PolygonStampedPublisher, Pose2DPublisher, PoseArrayPublisher, PosePublisher, PoseStampedPublisher, PoseWithCovariancePublisher, PoseWithCovarianceStampedPublisher, QoSProfilePublisher, QuaternionPublisher, QuaternionStampedPublisher, RangePublisher, RegionOfInterestPublisher, RelativeHumidityPublisher, ServiceEventInfoPublisher, ServicePublisher, SetLoggerLevelsResultPublisher, SetParametersResultPublisher, SolidPrimitivePublisher, StampedPublisherBase, StatePublisher, StatisticDataPointPublisher, StatisticDataTypePublisher, StringPublisher, TemperaturePublisher, TF2ErrorPublisher, TFMessagePublisher, TimePublisher, TimeReferencePublisher, TopicPublisher, TrajectoryPointPublisher, TrajectoryPublisher, TransformPublisher, TransformStampedPublisher, TransitionDescriptionPublisher, TransitionEventPublisher, TransitionPublisher, TwistPublisher, TwistStampedPublisher, TwistWithCovariancePublisher, TwistWithCovarianceStampedPublisher, TypeDescriptionPublisher, TypeHashPublisher, TypeSourcePublisher, UInt16MultiArrayPublisher, UInt16Publisher, UInt32MultiArrayPublisher, UInt32Publisher, UInt64MultiArrayPublisher, UInt64Publisher, UInt8MultiArrayPublisher, UInt8Publisher, UUIDPublisher, UVCoordinatePublisher, Vector3Publisher, Vector3StampedPublisher, VelocityStampedPublisher, VelocityWithCovarianceStampedPublisher, WrenchPublisher, and WrenchStampedPublisher

Status: Experimental Extension

Properties

Methods

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:

autoPublishpublishIntervalbehavior
false0Manual only. Call publish() (or a typed publish(msg) overload) explicitly. Field property writes update the stored message silently.
true0Publish 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> 0Rate-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> 0Publish 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.