Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Cannot marshal std::string with QDbus
Forum Updated to NodeBB v4.3 + New Features

Cannot marshal std::string with QDbus

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 4 Posters 1.7k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wpmccormick
    wrote on last edited by
    #3

    As I mentioned, it's an existing class, so changing is not the best option. My preference is to make work as is and I don't want to (shouldn't need to) make changes or have some wrapper.

    I found a number of examples/tutorials (e.g. this one) that show slots with return values, and none of these require Q_INVOKABLE. My understanding is that Q_INVOKABLE is for QML, which I'm not interested in at the moment (however that may come along at some point).

    Also, returning something from a method call seems to be rather well defined.

    Maybe you could look into when you have a chance, and/or pull in some other resources if need be?

    SGaistS 1 Reply Last reply
    0
    • W wpmccormick

      As I mentioned, it's an existing class, so changing is not the best option. My preference is to make work as is and I don't want to (shouldn't need to) make changes or have some wrapper.

      I found a number of examples/tutorials (e.g. this one) that show slots with return values, and none of these require Q_INVOKABLE. My understanding is that Q_INVOKABLE is for QML, which I'm not interested in at the moment (however that may come along at some point).

      Also, returning something from a method call seems to be rather well defined.

      Maybe you could look into when you have a chance, and/or pull in some other resources if need be?

      SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #4

      @wpmccormick said in qdbuscpp2xml: Unregistered input type in parameter list:

      I found a number of examples/tutorials (e.g. this one) that show slots with return values, and none of these require Q_INVOKABLE.

      As I wrote: usually they don't have return values. I didn't wrote slots required Q_INVOKABLE when they have return values.

      Q_INVOKABLE is used by QML but its existence predates QML by a very long time.

      As for your type problem, did you already read the The Qt D-Bus Type System chapter in Qt's documentation ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • W Offline
        W Offline
        wpmccormick
        wrote on last edited by
        #5

        Yes, I looked at that early on, but it was worth taking another look. From that, it appears that std::string is not supported, even though (from other docs/examples/tutorials) std::vector, std::list, and other like container types are supported. Still, it's such a well used type, I can't help but wonder if there still isn't someway to do it. Is there someone you might be able to ask?

        Also, direct copy/paste quote, you wrote "Methods that should return values and be usable by the meta object system are marked with Q_INVOKABLE."

        To me, that seems to imply that it's required, but I appreciate the confirmation that it is not.

        1 Reply Last reply
        0
        • fcarneyF Offline
          fcarneyF Offline
          fcarney
          wrote on last edited by
          #6

          If you are supporting existing calls that use those methods you can always add more methods:

            std::vector<std::string> getAvailableActions() const;
            std::vector<QString> getAvailableActions() const;
            std::vector<std::string> getActions(const std::string& state_name) const;
            std::vector<QString> getActions(const QString& state_name) const;
          

          Just have those new methods call the std::string versions. Yes it will be slower, but it maintains the old interface to talks to the new.

          C++ is a perfectly valid school of magic.

          W 1 Reply Last reply
          0
          • W Offline
            W Offline
            wpmccormick
            wrote on last edited by
            #7

            It's not a bad option, but still, std::string is as close as you can get to being a primitive data type, without being a primitive data type. Somehow QtDbus seem a little broken without it.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #8

              Just to clear something out: you can use std::string for your arguments however this will require some manual work. qdbus2xml is just a tool to help create the xml definitions. It was written with Qt in mind (since you are using the QDbus module) but currently does not support generating xml for custom types. However it doesn't mean that you can't use them. You should not put that tool and the module capabilities in the same bag.

              Have a look at this very interesting KDE tutorial about DBus and custom types.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              1
              • W Offline
                W Offline
                wpmccormick
                wrote on last edited by
                #9

                So that link is pretty much what I noted earlier in thread (part of the same tutorial) ... so yes, I've already been through that, and there's nothing there that I can see that will make std::string work. Unless there is some way to make std::string work, then I think the @fcarney solution is not a bad work-around; but it doesn't resolve the issue.

                My point on centering the discussion on the qdbuscpp2xml tool is that if it will not generate the XML for the interface that I need, then moving forward with cmake tools for generating the interface will be problematic as well.

                I think I should rename this topic to Cannot marshal std::string with QDbus.

                1 Reply Last reply
                0
                • fcarneyF fcarney

                  If you are supporting existing calls that use those methods you can always add more methods:

                    std::vector<std::string> getAvailableActions() const;
                    std::vector<QString> getAvailableActions() const;
                    std::vector<std::string> getActions(const std::string& state_name) const;
                    std::vector<QString> getActions(const QString& state_name) const;
                  

                  Just have those new methods call the std::string versions. Yes it will be slower, but it maintains the old interface to talks to the new.

                  W Offline
                  W Offline
                  wpmccormick
                  wrote on last edited by
                  #10

                  @fcarney now the issue is that qdbuscpp2xml doesn't generate an interface (XML) for the methods that return std:vector<QString>. I also tried QList<Qstring> and that doesn't work either.

                  I threw in a

                  Q_DECLARE_METATYPE(QList<QString>);
                  

                  just for good measure, and still nothing.

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #11

                    Use QStringList

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    2
                    • X Offline
                      X Offline
                      xupeidong
                      wrote on last edited by
                      #12

                      @wpmccormick
                      I will answer your 3rd question,you should write Q_CLASSINFO("D-Bus Interface", "org.foo.bar"),your interface name can be correct.
                      Now,I have a new question Unregistered input type in parameter list: ServiceStatusList when I use qdbuscpp2xml to generate xml.
                      Who can tell me what should I do,thanks a lot.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved