如何在 CycloneDDS C++ 中设置 QOS?

How to set QOS in CycloneDDS C++?

我正在使用 CycloneDDS C++ version,

正在尝试为写入器设置以下 QOS DDS_HISTORY_KEEP_ALL、DDS_DURABILITY_TRANSIENT_LOCAL、DDS_RELIABILITY_RELIABLE

我正在尝试在 dds 发布者中为数据编写器设置 Qos

dds::domain::DomainParticipant local_participant(domain::default_id());
dds::pub::Publisher local_publisher(local_participant);
dds::topic::Topic<DDSData::myData> topicMyData(local_participant, "DDS");

dds::pub::qos::DataWriterQos  QosW( dds_history_kind(DDS_HISTORY_KEEP_ALL), 
                                        dds_durability_kind(DDS_DURABILITY_TRANSIENT_LOCAL), 
                                        dds_reliability_kind(DDS_RELIABILITY_RELIABLE));

m_ReplyDataWriter = std::make_shared < dds::pub::DataWriter<DDSData::myData>>(local_publisher, topicMyData, QosW, NULL, ::dds::core::status::StatusMask::none());

带 Qos 的 DataWriter 构造函数

DataWriter(const dds::pub::Publisher& pub,
           const ::dds::topic::Topic<T>& topic,
           const dds::pub::qos::DataWriterQos& qos,
           dds::pub::DataWriterListener<T>* listener = NULL,
           const dds::core::status::StatusMask& mask = ::dds::core::status::StatusMask::none());

它不起作用,我在这里错过了什么?

Error   C2664'dds::pub::DataWriter<DDSData::myData,dds::pub::detail::DataWriter>::DataWriter(const dds::pub::DataWriter<DDSData::myData,dds::pub::detail::DataWriter> &)': cannot convert argument 3 from '_Ty' to 'const dds::pub::qos::DataWriterQos &'       

Check this out

错误是因为QoS设置不正确你可以试试下面的代码,

创建具有您自己的 QoS 的 DataWriter

dds::domain::DomainParticipant local_participant(domain::default_id());
dds::pub::Publisher local_publisher(local_participant);
dds::topic::Topic<DDSData::myData> topicMyData(local_participant, "DDS");       

dds::pub::qos::DataWriterQos dwqos = topicMyData.qos();

dwqos << dds_history_kind(DDS_HISTORY_KEEP_ALL) 
      << dds_durability_kind(DDS_DURABILITY_TRANSIENT_LOCAL) 
      << dds_reliability_kind(DDS_RELIABILITY_RELIABLE);

dds::pub::DataWriter<Foo::Type> writer2(local_publisher, topicMyData, dwqos);

//m_ReplyDataWriter = std::make_shared < dds::pub::DataWriter<DDSData::myData>>(local_publisher, topicMyData, dwqos, NULL, ::dds::core::status::StatusMask::none());