c++visual-studiodata-distribution-serviceqos

How to set QOS in CycloneDDS C++?


I am using CycloneDDS C++ version,

trying to set following QOS to the writer DDS_HISTORY_KEEP_ALL, DDS_DURABILITY_TRANSIENT_LOCAL, DDS_RELIABILITY_RELIABLE

I am trying to set Qos to data writer, in dds publisher

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());

DataWriter constructor with Qos

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());

it does not work what I am I missing here?

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 &'       

Solution

  • Check this out

    Error is because QoS is not set properly you can try below code,

    Creating a DataWriter with your own 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 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());