Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 372515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:13:05+00:00 2026-05-12T14:13:05+00:00

With a Qt DBus proxy built on QDbusAbstractInterface (via qdbusxml2cpp), what’s the best way

  • 0

With a Qt DBus proxy built on QDbusAbstractInterface (via qdbusxml2cpp), what’s the best way to handle the service/object you want to interface to not being available when you start? Note: I’m not interested in simply knowing it (you can use BlahService.isValid() to find that out); I want to be able to know if it’s valid, and know when it becomes valid so I can change state (and broadcast that state change with a signal), and on that state change do other stuff. Conversely, I want to know when it’s no longer valid for similar reasons.

Without tracking the state of the service:

#define CONNECT_DBUS_SIG(x,y) connect(blah,SIGNAL(x),this,SLOT(y))

// FIX - should watch for service, and also handle it going away and
// coming back
blah = new BlahService("com.xyzzy.BlahService", "/com/xyzzy/BlahService",
                           QDBusConnection::sessionBus(), this);
if (!blah)
    return 0;
if (blah.isValid())
{
    CONNECT_DBUS_SIG(foo(),Event_foo());
}
else
{
    // Since we aren't watching for registration, what can we do but exit?
}

Probably we need to watch for NameOwnerChanged on the DBus connection object – unless QT’s dbus code does this for us – and then when we get that signal change state, and if needed connect or disconnect the signals from the object.

All the examples I find either ignore the issue or simply exit if the server object doesn’t exist, and don’t deal with it going away. The Car/Controller Qt example at least notices if the server goes away and prints “Disconnected” if isValid() becomes false during use, but it’s polling isValid().

Added:

Note that QtDbusAbtractInterface registers for changes of ownership of the server (NameOwnerChanged), and updates isValid() when changes occur. So I suspect you can connect to that serverOwnerChanged signal directly to find out about changes to ownership and use that as an indicator to try again – though you won’t be able to trust isValid since it may be updated before or after you get signaled.

Alternatively (ugly) you can set up a timer and poll for isValid().

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:13:06+00:00Added an answer on May 12, 2026 at 2:13 pm

    Ok, since no one answered, I’ve found the answer in the meantime:

    You want to watch NameOwnerChanged:

    // subscribe to notifications about when a service is registered/unregistered
       connect(QDBusConnection::sessionBus().interface(),
               SIGNAL(serviceOwnerChanged(QString,QString,QString)),
               this,SLOT(serviceOwnerChanged(QString,QString,QString)));
    

    and

    void 
    VcsApplicationController::serviceOwnerChanged(const QString &name,
                                                  const QString &oldOwner,
                                                  const QString &newOwner)
    {
        Q_UNUSED(oldOwner);
        if (name == "com.foo.bar.FooService")
        {
            qLog(Whatever) << "serviceOwnerChanged" << name << oldOwner << newOwner;
            if (!newOwner.isEmpty())
            {
                // New owner in town
                emit Initialized();
                // or if you control the interface and both sides, you can wait for
                // a "Ready()" signal before declaring FooService ready for business.
            }
            else
            {
                // indicate we've lost connection, etc
                emit Uninitialized();
            }
        }
    }
    

    Note that there may be race conditions with doing methods on FooService from within serviceOwnerChanged – I’m not sure yet if they’re a side-effect of the binding (dbus-c++ in my test case), or inherent in the design of dbus (possible – no on on the dbus mailing list will answer the question). If there is a real race condition, you can wait on a Ready()/whatever signal, if you control the DBus API. If you don’t control the other end, you can add a very short delay or you can also watch AddMatch() to make sure the new owner has added a match on the name as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using python-dbus to interface with HAL, and I need to find a device's
I'm using python-dbus and cherrypy to monitor USB devices and provide a REST service
I am using DBus in a project. I understand from DBus specification that for
I am using dbus to get the current playing song from Songbird Media Player
I am having an issue with DBus: I register with DBus dbus_bus_get() method :
Is it possible to integrate asyncore with dbus through the same main loop ?
Is there an equivalent to Linux DBus on OSX? I mean, is there a
basically the problem is, that the only way to get all instances of VLC
In all python dbus documentations there are info on how to export objects, interfaces,
Is there a practical way to set the global status message in Pidgin for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.