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. QDBusReply::operator Type() const usage
Forum Update on Monday, May 27th 2025

QDBusReply::operator Type() const usage

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 593 Views
  • 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.
  • E Offline
    E Offline
    Eligijus
    wrote on last edited by Eligijus
    #1

    Hello,

    I'm trying to follow this example in the QDBusReply documentation.

    If the remote method call cannot fail, you can skip the error checking:

    QString reply = interface->call("RemoteMethod");
    

    But this example does not compile for me. Am I missing something?
    There is overloaded operator QDBusReply::operator Type() const. And closest I could get to example that compiles is:

    QString reply = QDBusReply<QString>(interface->call("RemoteMethod"));
    
    jsulmJ 1 Reply Last reply
    0
    • E Eligijus

      Hello,

      I'm trying to follow this example in the QDBusReply documentation.

      If the remote method call cannot fail, you can skip the error checking:

      QString reply = interface->call("RemoteMethod");
      

      But this example does not compile for me. Am I missing something?
      There is overloaded operator QDBusReply::operator Type() const. And closest I could get to example that compiles is:

      QString reply = QDBusReply<QString>(interface->call("RemoteMethod"));
      
      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Eligijus What example do you mean? If it does not compile: what is the compiler error?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Eligijus
        wrote on last edited by
        #3

        Sorry I had a wrong link in QDBusReply documentation it's fixed now.
        Error:

        /home/eligijus/BigDisk/QtProjects/bigbrother2/gui_application/systemd1service.cpp:510: error: conversion from ‘QDBusMessage’ to non-scalar type ‘QString’ requested
             QString s = call("GetDefaultTarget");
                             ^
        
        jsulmJ 1 Reply Last reply
        0
        • E Eligijus

          Sorry I had a wrong link in QDBusReply documentation it's fixed now.
          Error:

          /home/eligijus/BigDisk/QtProjects/bigbrother2/gui_application/systemd1service.cpp:510: error: conversion from ‘QDBusMessage’ to non-scalar type ‘QString’ requested
               QString s = call("GetDefaultTarget");
                               ^
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Eligijus Why are you trying to cast QDBusMessage to a QString? What do you want to achieve?

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          E 1 Reply Last reply
          0
          • jsulmJ jsulm

            @Eligijus Why are you trying to cast QDBusMessage to a QString? What do you want to achieve?

            E Offline
            E Offline
            Eligijus
            wrote on last edited by
            #5

            @jsulm I'm trying to follow an example from here http://doc.qt.io/qt-5/qdbusreply.html#details

            Detailed Description
            The QDBusReply class stores the reply for a method call to a remote object.

            A QDBusReply object is a subset of the QDBusMessage object that represents a method call's reply. It contains only the first output argument or the error code and is used by QDBusInterface-derived classes to allow returning the error code as the function's return argument.

            It can be used in the following manner:

            QDBusReply<QString> reply = interface->call("RemoteMethod");
            if (reply.isValid())
                // use the returned value
                useValue(reply.value());
            else
                // call failed. Show an error condition.
                showError(reply.error());
            

            If the remote method call cannot fail, you can skip the error checking:

            QString reply = interface->call("RemoteMethod");
            

            However, if it does fail under those conditions, the value returned by QDBusReply::value() is a default-constructed value. It may be indistinguishable from a valid return value.

            QDBusReply objects are used for remote calls that have no output arguments or return values (i.e., they have a "void" return type). Use the isValid() function to test if the reply succeeded.

            And my code QString s = call("GetDefaultTarget"); (it's the same as QString reply = interface->call("RemoteMethod");) does not compile

            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