As written In the title, I am trying to add my custom type (calles TestType) to a d-bus based interfaces. However when compyling the code, I get an error message in the generated adaptor code
TestType has not been declared.
I have searched the internet and found some examples how it should work. So in the XML protocol file (Test.xml), I have added following method:
<method name="testMethod">
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="TestType"/>
<arg name="TestType" type="(i)" direction="in"/>
</method>
<method name="testMethod">
<annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="TestType"/>
<arg name="TestType" type="(i)" direction="in"/>
</method>
To copy to clipboard, switch view to plain text mode
In my header file I have following (TestType.hpp)
#ifndef TESTTYPE_HPP
#define TESTTYPE_HPP
#include <QDBusArgument>
#include <QDBusMetaType>
#include <QObject>
enum class TestType
{
...whatever
};
Q_DECLARE_METATYPE(TestType)
inline void registerType()
{
qRegisterMetaType<TestType>("TestType");
qDBusRegisterMetaType<TestType>();
}
#endif // TESTTYPE_HPP
#ifndef TESTTYPE_HPP
#define TESTTYPE_HPP
#include <QDBusArgument>
#include <QDBusMetaType>
#include <QObject>
enum class TestType
{
...whatever
};
QDBusArgument &operator<<(QDBusArgument &argument, const TestType &testType);
const QDBusArgument &operator>>(const QDBusArgument &argument, const TestType &testType);
Q_DECLARE_METATYPE(TestType)
inline void registerType()
{
qRegisterMetaType<TestType>("TestType");
qDBusRegisterMetaType<TestType>();
}
#endif // TESTTYPE_HPP
To copy to clipboard, switch view to plain text mode
The according .cpp file looks like this:
#include "TestType.hpp"
#include <QDBusMetaType>
{
argument.beginStructure();
argument << testType;
argument.endStructure();
return argument;
}
{
argument.beginStructure();
argument >> testType;
argument.endStructure();
return argument;
}
int main(int argc, char *argv[])
{
registerType();
}
#include "TestType.hpp"
#include <QDBusMetaType>
QDBusArgument &operator<<(QDBusArgument &argument, const TestType &testType)
{
argument.beginStructure();
argument << testType;
argument.endStructure();
return argument;
}
const QDBusArgument &operator>>(const QDBusArgument &argument, const TestType &testType)
{
argument.beginStructure();
argument >> testType;
argument.endStructure();
return argument;
}
int main(int argc, char *argv[])
{
registerType();
}
To copy to clipboard, switch view to plain text mode
I will try to copy only the relevant lines from my cmake file:
set(SOURCES TestType.cpp AnotherTestClass.cpp Test.xml)
qt5_add_dbus_adaptor(SOURCES Test.xml
AnotherTestClass.hpp AnotherTestClass)
set(SOURCES TestType.cpp AnotherTestClass.cpp Test.xml)
qt5_add_dbus_adaptor(SOURCES Test.xml
AnotherTestClass.hpp AnotherTestClass)
To copy to clipboard, switch view to plain text mode
So when the generated source code of the adaptor classes is created, I get the mentioned error. In my understanding, I have to specify somehow that the generated source files include my header ? IF yes, I don't know how to do it, or am I missing something completely? I am using qt 5.12 on ubuntu.
Bookmarks