Public bug reported:

Consider the following example:

#include <QtCore>
#include <QtDBus>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    QDBusInterface dbus("org.freedesktop.DBus",
                        "/org/freedesktop/DBus",
                        "org.freedesktop.DBus",
                        QDBusConnection::sessionBus());

    if (!dbus.isValid())
    {
        qDebug() << "IFACE IS NOT VALID" << dbus.lastError().message();
        return 1;
    }

    QDBusReply<QStringList> servicesReply = dbus.call("ListNames");

    if (!servicesReply.isValid())
    {
        qDebug() << "REPLY IS NOT VALID" << servicesReply.error().message();
        return 2;
    }

    qDebug() << servicesReply.value();
}

Compile and run. It prints

IFACE IS NOT VALID ""

The issue here is that QDBusInterface::isValid() returns false, however
it's still possible to call its methods. If I comment out the "if
(!dbus.isValid())" line, it starts to work fine:

#include <QtCore>
#include <QtDBus>

int main(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);

    QDBusInterface dbus("org.freedesktop.DBus",
                        "/org/freedesktop/DBus",
                        "org.freedesktop.DBus",
                        QDBusConnection::sessionBus());
/*
    if (!dbus.isValid())
    {
        qDebug() << "IFACE IS NOT VALID" << dbus.lastError().message();
        return 1;
    }
*/
    // WORKS FINE!
    QDBusReply<QStringList> servicesReply = dbus.call("ListNames");

    if (!servicesReply.isValid())
    {
        qDebug() << "REPLY IS NOT VALID" << servicesReply.error().message();
        return 2;
    }

    qDebug() << servicesReply.value();
}

In Ubuntu 16.04 it worked fine. All updates have been installed.

** Affects: qtbase-opensource-src (Ubuntu)
     Importance: Undecided
         Status: New


** Tags: bionic

** Attachment added: "dbus-list.tar.gz"
   
https://bugs.launchpad.net/bugs/1776446/+attachment/5151676/+files/dbus-list.tar.gz

** Description changed:

  Consider the following example:
  
  #include <QtCore>
  #include <QtDBus>
  
  int main(int argc, char *argv[])
  {
-     QCoreApplication app(argc, argv);
+     QCoreApplication app(argc, argv);
  
-     QDBusInterface dbus("org.freedesktop.DBus",
-                         "/org/freedesktop/DBus",
-                         "org.freedesktop.DBus",
-                         QDBusConnection::sessionBus());
+     QDBusInterface dbus("org.freedesktop.DBus",
+                         "/org/freedesktop/DBus",
+                         "org.freedesktop.DBus",
+                         QDBusConnection::sessionBus());
  
-     if (!dbus.isValid())
-     {
-         qDebug() << "IFACE IS NOT VALID" << dbus.lastError().message();
-         return 1;
-     }
+     if (!dbus.isValid())
+     {
+         qDebug() << "IFACE IS NOT VALID" << dbus.lastError().message();
+         return 1;
+     }
  
-     QDBusReply<QStringList> servicesReply = dbus.call("ListNames");
-                                                 
-     if (!servicesReply.isValid())
-     {
-         qDebug() << "REPLY IS NOT VALID" << servicesReply.error().message();
-         return 2;
-     }
+     QDBusReply<QStringList> servicesReply = dbus.call("ListNames");
  
-     qDebug() << servicesReply.value();
+     if (!servicesReply.isValid())
+     {
+         qDebug() << "REPLY IS NOT VALID" << servicesReply.error().message();
+         return 2;
+     }
+ 
+     qDebug() << servicesReply.value();
  }
  
  Compile and run. It prints
  
  IFACE IS NOT VALID ""
  
  The issue here is that QDBusInterface::isValid() returns false, however
  it's still possible to call its methods. If I comment out the "if
  (!dbus.isValid())" line, it starts to work fine:
  
  #include <QtCore>
  #include <QtDBus>
  
  int main(int argc, char *argv[])
  {
-     QCoreApplication app(argc, argv);
+     QCoreApplication app(argc, argv);
  
-     QDBusInterface dbus("org.freedesktop.DBus",
-                         "/org/freedesktop/DBus",
-                         "org.freedesktop.DBus",
-                         QDBusConnection::sessionBus());
+     QDBusInterface dbus("org.freedesktop.DBus",
+                         "/org/freedesktop/DBus",
+                         "org.freedesktop.DBus",
+                         QDBusConnection::sessionBus());
  /*
-     if (!dbus.isValid())
-     {
-         qDebug() << "IFACE IS NOT VALID" << dbus.lastError().message();
-         return 1;
-     }
+     if (!dbus.isValid())
+     {
+         qDebug() << "IFACE IS NOT VALID" << dbus.lastError().message();
+         return 1;
+     }
  */
-     // WORKS FINE!
-     QDBusReply<QStringList> servicesReply = dbus.call("ListNames");
+     // WORKS FINE!
+     QDBusReply<QStringList> servicesReply = dbus.call("ListNames");
  
-     if (!servicesReply.isValid())
-     {
-         qDebug() << "REPLY IS NOT VALID" << servicesReply.error().message();
-         return 2;
-     }
+     if (!servicesReply.isValid())
+     {
+         qDebug() << "REPLY IS NOT VALID" << servicesReply.error().message();
+         return 2;
+     }
  
-     qDebug() << servicesReply.value();
+     qDebug() << servicesReply.value();
  }
+ 
+ In Ubuntu 16.04 it worked fine. All updates have been installed.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/1776446

Title:
  QDBusInterface is able to connect to org.freedesktop.DBus, but its
  status is invalid

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/qtbase-opensource-src/+bug/1776446/+subscriptions

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to