RTI Connext Modern C++ API  Version 6.1.0
Qos Provider Use Cases

How to use dds::core::QosProvider to access XML QoS profiles. More...

How to use dds::core::QosProvider to access XML QoS profiles.

Managing Qos Profiles

This section provides several examples on how to use a dds::core::QosProvider to load QoS profiles from XML. The class documentation provides general usage information.

These examples use the following file, ExampleQos.xml, which defines only the EntityName QoS policy for the DomainParticipant and DataWriter to illustrate how the profiles are loaded:

<?xml version="1.0"?>
<dds xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<qos_library name="MyLibrary">
<qos_profile name="MyProfile" is_default_qos="true">
<qos_library name="MySecondLibrary">
<qos_profile name="MySecondProfile">

The example code shows how to create a QosProvider, load QoS profiles from the provider, and create entities with those QoS values:

// Load the contents of an XML file:
dds::core::QosProvider my_provider("ExampleQos.xml");
// Create a participant with the default profile:
auto participant_qos = my_provider.participant_qos();
dds::domain::DomainParticipant participant(0, participant_qos);
// This prints ExampleParticipantName because MyLibrary::MyProfile is marked
// with is_default_qos="true"
std::cout << participant.qos().policy<EntityName>().name().value()
<< std::endl;
// Load a specific profile. This time it prints SecondExampleParticipantName
participant_qos =
std::cout << participant_qos.policy<EntityName>().name().value()
<< std::endl;
// Change the default profile:
// Now when the profile is not specified, participant_qos() looks at
// "MySecondLibrary::MySecondProfile", printing SecondExampleParticipantName
participant_qos = my_provider.participant_qos();
std::cout << participant_qos.policy<EntityName>().name().value()
<< std::endl;
// Create a topic, publisher and writer:
dds::topic::Topic<Foo> topic(participant, "Example Foo");
dds::pub::Publisher publisher(participant);
// Prints SecondExamplePublicationName
std::cout << writer.qos().policy<EntityName>().name().value()
<< std::endl;
// If you don't want to specify the QoS argument for each writer you create
// you can set the default value:
dds::pub::DataWriter<Foo> other_writer(publisher, topic);
// Prints ExamplePublicationName
std::cout << writer.qos().policy<EntityName>().name().value() << std::endl;
// You can also load the QoS profiles from a string:
const char * my_xml_str =
"<qos_library name=\"MyThirdLibrary\">"
"<qos_profile name=\"MyThirdProfile\">"
// In this case we're also specifying which profile we want to load by
// default in the constructor
dds::core::QosProvider my_provider2(
// This prints ThirdExampleParticipantName
participant_qos = my_provider2.participant_qos();
std::cout << participant_qos.policy<EntityName>().name().value()
<< std::endl;
// You can also examine which libraries and profiles that have been
// loaded:
auto libraries = my_provider.extensions().qos_profile_libraries();
for (const std::string& library : libraries) {
std::cout << library << std::endl;
auto profiles = my_provider.extensions().qos_profiles(library);
for (const std::string& profile : profiles) {
std::cout << " -" << profile << std::endl;
See also
Create a DynamicType from an XML description
XML Application Creation

The Default Qos Provider

This example shows how to configure the default QosProvider:

// We're going to configure the default QoS Provider to load ExampleQos.xml
// and to ignore the NDDS_QOS_PROFILES environment variable and the file
params.url_profile({ "ExampleQos.xml" });
// To ensure that the new configuration takes effect before any other
// profiles are loaded, set the new parameters before accessing
// QosProvider::Default().
dds::domain::DomainParticipant participant1(0, default_provider.participant_qos());
// Prints "ExampleParticipantName"
std::cout << participant1.qos().policy<EntityName>().name().value()
<< std::endl;
// Change the default profile
dds::domain::DomainParticipant participant2(1, default_provider.participant_qos());
// Prints "SecondExampleParticipantName"
std::cout << participant2.qos().policy<EntityName>().name().value()
<< std::endl;
// Reset the QosProviderParams for the default QosProvider
// This participant will not have a participant name (the default
// RTI Connext value) because we reset the default QosProviderParams,
// meaning that the value for string_profile is empty and the above example
// XML Qos profile is not loaded.
dds::domain::DomainParticipant participant3(2, default_provider.participant_qos());
// Prints false
std::cout << std::boolalpha
<< participant2.qos().policy<EntityName>().name().has_value()
<< std::endl;