Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This is my first time using DBus so I'm not entirely sure if I'm going about this the right way. I'm attempting to connect the the Ubuntu One DBus service and obtain login credentials for my app, however the slots I've connected to the DBus return signals detailed here never seem to be firing, despite a positive result being returned during the connection.

Before I start looking for errors in the details relating to this specific service, could someone please tell me if this code would even work in the first place, or if I'm done something wrong here?

int main()
{
    UbuntuOneDBus *u1Dbus = new UbuntuOneDBus;
    u1Dbus->init()
}

class UbuntuOneDBus : public QObject
{
  Q_OBJECT

  QString busName;
  QString path;
  QString interface;
  QString method;
  QString signature;

  void connectReturnSignals();

private slots:
  void credentialsFound();
  void credentialsNotFound();
  void credentialsError();

public:
  UbuntuOneDBus();

  void init();
};

UbuntuOneDBus::UbuntuOneDBus()
{
  busName = "com.ubuntuone.Credentials";
  path = "/credentials";
  interface = "com.ubuntuone.CredentialsManagement";
  method = "register";
  signature = "a{ss}";

  connectReturnSignals();
}

void UbuntuOneDBus::init()
{
  QDBusMessage message = QDBusMessage::createMethodCall( busName, path, interface, method );
  QDBusConnection::sessionBus().send( message );
}

void UbuntuOneDBus::connectReturnSignals()
{
  QDBusConnection::sessionBus().connect( busName, path, interface, "CredentialsFound", this, SLOT( credentialsFound() ) );
  QDBusConnection::sessionBus().connect( busName, path, interface, "CredentialsNotFound", this, SLOT( credentialsNotFound() ) );
  QDBusConnection::sessionBus().connect( busName, path, interface, "CredentialsError", this, SLOT( credentialsError() ) );
}

void UbuntuOneDBus::credentialsFound()
{
  qDebug() << "Credentials found";
}

void UbuntuOneDBus::credentialsNotFound()
{
  std::cout << "Credentials not found" << std::endl;
}

void UbuntuOneDBus::credentialsError()
{
  std::cout << "Credentials error" << std::endl;
}
share|improve this question
    
Have you declare this methods: - credentialsFound - credentialsNotFound As slots in the .h file? If that is the case, could you provide some repository or something to obtain the code and debug it if necessary? –  gatox Jun 26 '12 at 13:03
    
Thanks for your reply, I indeed declared them as slots in the header file. I have updated the code snippet to include the entire class, both declaration and definition, as well as the main() function from which it's invoked. –  Chris Wilson Jun 30 '12 at 17:29
add comment

2 Answers

up vote 2 down vote accepted
+200

The signature argument to the connect method looks wrong. Funny as it looks, it should be just "a{ss}".

That already means "array of dictionary items with string as key and string as value", so the added part "(Dict of {String, String})" may happen to be interpreted the wrong way. Similarly, the signature for the CredentialsNotFound D-Bus signal should not be "(nothing)", it should be just an empty string like "".

To familiarize yourself with the other data types that D-Bus offers try a tutorial like this: http://dbus.freedesktop.org/doc/dbus-python/doc/tutorial.html#data-types

share|improve this answer
    
Thanks a lot for your help, but that doesn't seem to have been the issue. I actually started using the connect() function without the signature parameter but that wasn't working either. –  Chris Wilson Jun 30 '12 at 17:26
add comment

I'm not entirely sure how slots work in Qt exactly, but my understanding is you still need to define the function to have the correct signature to match the signature of the DBus signals. So in the case of Credentials Found, it needs to take a hash/map of string keys and values, assuming that QtDBus converts the "a{ss}" signature into the correct data type automatically. I suspect such slot functions also need to accept any standard arguments provided by QtDBus itself.

I also found this quick tutorial from Nokia, which might be helpful: http://www.developer.nokia.com/Community/Wiki/QtDbus_quick_tutorial

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.