Cannot add custom type to d-bus protocol
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
Quote:
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:
Code:
<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)
Code:
#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
The according .cpp file looks like this:
Code:
#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();
}
I will try to copy only the relevant lines from my cmake file:
Code:
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.
Re: Cannot add custom type to d-bus protocol
Your introspection XML says that the argument is named TestType, so the generated code will look like
Code:
void testType(TestType TestType);
That's like writing
I.e. the argument name must not be a type name.
Cheers,
_
Re: Cannot add custom type to d-bus protocol
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 :/
Re: Cannot add custom type to d-bus protocol
Have you tried including TestType.hpp in AnotherTestClass.hpp?
Cheers,
_
Re: Cannot add custom type to d-bus protocol
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 classes, and it does not know about mine :/.
Quote:
Originally Posted by
anda_skoa
Have you tried including TestType.hpp in AnotherTestClass.hpp?
Cheers,
_
Re: Cannot add custom type to d-bus protocol
Quote:
Originally Posted by
bananahana
The generated header file of dbus only includes some
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,
_