PDA

View Full Version : Cannot add custom type to d-bus protocol



bananahana
5th August 2019, 16:03
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>


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
};

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



The according .cpp file looks like this:



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


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)


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.

anda_skoa
5th August 2019, 17:23
Your introspection XML says that the argument is named TestType, so the generated code will look like



void testType(TestType TestType);


That's like writing


void foo(int int);


I.e. the argument name must not be a type name.

Cheers,
_

bananahana
6th August 2019, 09:07
Oh yes, you are right. But I did it correctly in my code, this was a typo here when I changed the variable names. So my problem still remains :/

anda_skoa
6th August 2019, 10:03
Have you tried including TestType.hpp in AnotherTestClass.hpp?

Cheers,
_

bananahana
6th August 2019, 11:20
That seemed like a good idea, I have tried it but it also does not work. The generated header file of dbus only includes some
QtCore classes, and it does not know about mine :/.


Have you tried including TestType.hpp in AnotherTestClass.hpp?

Cheers,
_

anda_skoa
6th August 2019, 19:38
The generated header file of dbus only includes some
QtCore classes, and it does not know about mine :/.

It should also have included the header you passed.

Can you check which command is actually executed during build?

$ make VERBOSE=1

It should be something like

qdbusxml2cpp Test.xml -i AnotherTestClass.hpp -a AnotherTestClass

Maybe you need to change header name so that it doesn't have the same name as the class that is being generated.

Cheers,
_