QIfRemoteObjectsConfig Class

The QIfRemoteObjectsConfig helps to maintain config options for remote object based servers. More...

Header: #include <QIfRemoteObjectsConfig>
qmake: QT += interfaceframework

Public Functions

bool enableRemoting(const QString &module, const QString &interface, QObject *object)
bool enableRemoting(const QString &module, const QString &interface, const QUrl &fallbackUrl, QObject *object)
QRemoteObjectHost *host(const QUrl &url)
QRemoteObjectHost *host(const QString &module, const QString &interface, const QUrl &fallbackUrl = QUrl())
void parseConfigFile(const QString &confFilePath)
void parseLegacyConfigFile()
bool reportErrorsOnStdErr() const
void setDefaultServerUrl(const QUrl &defaultServerUrl)
void setReportErrorsOnStdErr(bool enabled)

Detailed Description

The QIfRemoteObjectsConfig class can used to retrieve a correctly configured QRemoteObjectHost for the provided interface.

In the simplest form it can be used like this in your main.cpp:

#include <QCoreApplication>

#include "myapi.h"
#include "core.h"

#include <QIfRemoteObjectsConfig>

using namespace Qt::StringLiterals;

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    QIfRemoteObjectsConfig config;

    MyApi service;
    config.enableRemoting(u"Example.If.RemoteModule"_s, "MyApi"_s, &service);

    return app.exec();
}

This will make the service accessible using the default url build from the module parameter. In this case: local://RemoteModule

Manage Remoting URLs

Usually multiple interfaces are defined within a module and by using the default urls those services are always served by a single module URL using a local socket.

To change the URL of all services a default server can be set using the setDefaultServerUrl() function.

For more flexibility, a config file can be provided using the parseConfigFile function. This allows to set the used URL on interface or module level. Defining module URLs allows the same config file to be reused by multiple servers where each server hosts all interfaces of a single module.

Legacy Config support

Until 6.7 the autogenerated code of a QtRemoteObject based server used a file called "server.conf" in the current directory to read the URLs used for remoting a service.

Reading this config file can be enabled by using the parseLegacyConfigFile() function.

See also the useGeneratedMain QFace Annotation to let ifcodegen generate a main.cpp with fully setup QIfRemoteObjectsConfig.

Member Function Documentation

bool QIfRemoteObjectsConfig::enableRemoting(const QString &module, const QString &interface, QObject *object)

Enables remoting of the passed object using a QRemoteObjectHost instance with a preconfigured url.

Returns true if remoting is successfully enabled for the passed object.

See host() for more information on how module and interface influence the effective url.

See also enableRemoting.

bool QIfRemoteObjectsConfig::enableRemoting(const QString &module, const QString &interface, const QUrl &fallbackUrl, QObject *object)

Enables remoting of the passed object using a QRemoteObjectHost instance with a preconfigured url.

Returns true if remoting is successfully enabled for the passed object.

See host() for more information on how module, interface and fallbackUrl influence the effective url.

See also enableRemoting.

QRemoteObjectHost *QIfRemoteObjectsConfig::host(const QUrl &url)

Returns a QRemoteObjectHost with a preconfigured url.

See also host.

QRemoteObjectHost *QIfRemoteObjectsConfig::host(const QString &module, const QString &interface, const QUrl &fallbackUrl = QUrl())

Returns a QRemoteObjectHost with a preconfigured url.

The url is specific to the provided module and interface arguments and can be modified using the setDefaultServerUrl() function or by using one of the config files.

If multiple values are configured the urls are resolved in the following order:

  1. interface
  2. module
  3. legacy Registry key
  4. defaultServer
  5. fallbackUrl argument

If none of these settings have been configured, or invalid urls were passed, a default url is built using the module argument.

See also host.

void QIfRemoteObjectsConfig::parseConfigFile(const QString &confFilePath)

Parses the config file at confFilePath and uses the stored module and interface specific urls when requested by host().

See also host().

void QIfRemoteObjectsConfig::parseLegacyConfigFile()

Parses the legacy "server.conf" file in the current directory or at the location set by the SERVER_CONF_PATH environment variable.

bool QIfRemoteObjectsConfig::reportErrorsOnStdErr() const

Returns true, if error logging to stderr for the created QRemoteObjectHost instances is enabled. Defaults to true.

See also setReportErrorsOnStdErr().

void QIfRemoteObjectsConfig::setDefaultServerUrl(const QUrl &defaultServerUrl)

Sets the defaultServerUrl, which will be used for all services which don't have a server set either for the interface or the module inside a config file.

void QIfRemoteObjectsConfig::setReportErrorsOnStdErr(bool enabled)

Enables logging of all errors reported by the created QRemoteObjectHost instances on stderr.

Setting enabled to false disables the logging.

See also reportErrorsOnStdErr.

© 2024 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.