Results 1 to 6 of 6

Thread: Cannot add custom type to d-bus protocol

  1. #1
    Join Date
    Aug 2019
    Posts
    3
    Qt products
    Qt/Embedded

    Default 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
    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:
    Qt Code:
    1. <method name="testMethod">
    2. <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="TestType"/>
    3. <arg name="TestType" type="(i)" direction="in"/>
    4. </method>
    To copy to clipboard, switch view to plain text mode 

    In my header file I have following (TestType.hpp)

    Qt Code:
    1. #ifndef TESTTYPE_HPP
    2. #define TESTTYPE_HPP
    3.  
    4. #include <QDBusArgument>
    5. #include <QDBusMetaType>
    6. #include <QObject>
    7.  
    8. enum class TestType
    9. {
    10. ...whatever
    11. };
    12.  
    13. QDBusArgument &operator<<(QDBusArgument &argument, const TestType &testType);
    14. const QDBusArgument &operator>>(const QDBusArgument &argument, const TestType &testType);
    15.  
    16. Q_DECLARE_METATYPE(TestType)
    17.  
    18. inline void registerType()
    19. {
    20. qRegisterMetaType<TestType>("TestType");
    21. qDBusRegisterMetaType<TestType>();
    22. }
    23.  
    24. #endif // TESTTYPE_HPP
    To copy to clipboard, switch view to plain text mode 

    The according .cpp file looks like this:

    Qt Code:
    1. #include "TestType.hpp"
    2. #include <QDBusMetaType>
    3.  
    4. QDBusArgument &operator<<(QDBusArgument &argument, const TestType &testType)
    5. {
    6. argument.beginStructure();
    7. argument << testType;
    8. argument.endStructure();
    9.  
    10. return argument;
    11. }
    12.  
    13. const QDBusArgument &operator>>(const QDBusArgument &argument, const TestType &testType)
    14. {
    15. argument.beginStructure();
    16. argument >> testType;
    17. argument.endStructure();
    18.  
    19. return argument;
    20. }
    21.  
    22. int main(int argc, char *argv[])
    23. {
    24. registerType();
    25. }
    To copy to clipboard, switch view to plain text mode 

    I will try to copy only the relevant lines from my cmake file:

    Qt Code:
    1. set(SOURCES TestType.cpp AnotherTestClass.cpp Test.xml)
    2.  
    3. qt5_add_dbus_adaptor(SOURCES Test.xml
    4. 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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default 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

    Qt Code:
    1. void testType(TestType TestType);
    To copy to clipboard, switch view to plain text mode 

    That's like writing
    Qt Code:
    1. void foo(int int);
    To copy to clipboard, switch view to plain text mode 

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

    Cheers,
    _

  3. #3
    Join Date
    Aug 2019
    Posts
    3
    Qt products
    Qt/Embedded

    Default 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 :/

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Cannot add custom type to d-bus protocol

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

    Cheers,
    _

  5. #5
    Join Date
    Aug 2019
    Posts
    3
    Qt products
    Qt/Embedded

    Default 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
    Qt Code:
    1. QtCore
    To copy to clipboard, switch view to plain text mode 
    classes, and it does not know about mine :/.

    Quote Originally Posted by anda_skoa View Post
    Have you tried including TestType.hpp in AnotherTestClass.hpp?

    Cheers,
    _

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,420
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Cannot add custom type to d-bus protocol

    Quote Originally Posted by bananahana View Post
    The generated header file of dbus only includes some
    Qt Code:
    1. QtCore
    To copy to clipboard, switch view to plain text mode 
    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,
    _

Similar Threads

  1. Getting Device Interface Protocol (SCSI or ATA protocol)
    By Ryuuji in forum General Programming
    Replies: 1
    Last Post: 18th July 2013, 08:37
  2. Custom Type Sending
    By iprion in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2013, 11:19
  3. QTreeView with custom type
    By jajdoo in forum Newbie
    Replies: 1
    Last Post: 25th September 2011, 20:27
  4. QVariant custom type.
    By hickscorp in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2010, 14:23
  5. Qt Jambi Webkit Custom Protocol
    By tgl in forum Qt Programming
    Replies: 3
    Last Post: 2nd July 2009, 17:09

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.