Results 1 to 4 of 4

Thread: <QtDBus/QtDBus> / <dbus/dbus.h>

  1. #1
    Join Date
    May 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default <QtDBus/QtDBus> / <dbus/dbus.h>

    1. Is it possible to send a message via <dbus/dbus.h> and receive it using Qt one ?
    2. Is it possible to send a message as root and receive it from app which runs on different user ? (linux)

    1a. I have troubles to read the message that's why the question. This is my code:

    Send <dbus/dbus.h>
    Qt Code:
    1. dbus_error_init(&_dbusError);
    2. _dbusConnection = dbus_bus_get(DBUS_BUS_SYSTEM, &_dbusError);
    3.  
    4. if (dbus_error_is_set(&_dbusError)) {
    5. logger("Dbus Connection Error");
    6. dbus_error_free(&_dbusError);
    7. return;
    8.  
    9. } else {
    10. logger("Dbus Connected");
    11. }
    12.  
    13. _dbusMessage = dbus_message_new_signal("/", "com.app.message", "app");
    14. if (NULL == _dbusMessage) {
    15. logger("Message Null");
    16. exit(1);
    17. } else {
    18. logger("Dbus new signal");
    19. }
    20.  
    21. dbus_message_iter_init_append(_dbusMessage, &_dbusMessageIter);
    22. if (!dbus_message_iter_append_basic(&_dbusMessageIter, DBUS_TYPE_STRING, &message)) {
    23. logger("Couldn't append dbus message");
    24. } else {
    25. stringstream s;
    26. s << message;
    27. logger("Dbus Messgae append - " + s.str());
    28. }
    29.  
    30. if (!dbus_connection_send(_dbusConnection, _dbusMessage, &_dbusSerial)) {
    31. logger("Couldn't send dbus message");
    32. } else {
    33. logger("Dbus Messgae sent");
    34. }
    35.  
    36. dbus_connection_flush(_dbusConnection);
    37. dbus_message_unref(_dbusMessage);
    To copy to clipboard, switch view to plain text mode 

    Read <QtDBus/QtDBus> example from ping pong

    Qt Code:
    1. QString Pong::ping(const QString &arg)
    2. {
    3. QMetaObject::invokeMethod(QCoreApplication::instance(), "quit");
    4. return QString("ping(\"%1\") got called").arg(arg);
    5. }
    6.  
    7. int main(int argc, char **argv)
    8. {
    9. QCoreApplication app(argc, argv);
    10.  
    11. if (!QDBusConnection::sessionBus().isConnected()) {
    12. cout << "Cannot connect to the D-Bus session bus" << endl;
    13. return 1;
    14. }
    15.  
    16. if (!QDBusConnection::sessionBus().registerService("com.app.message")) {
    17. cout << "error" << endl;
    18. exit(1);
    19. }
    20.  
    21. Pong pong;
    22. QDBusConnection::sessionBus().registerObject("/", &pong, QDBusConnection::ExportAllSlots);
    23.  
    24.  
    25. app.exec();
    26. return 0;
    27. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for looking

  2. #2
    Join Date
    May 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: <QtDBus/QtDBus> / <dbus/dbus.h>

    really no one, is it not newbie... ?

  3. #3
    Join Date
    Jul 2011
    Location
    Brasil
    Posts
    39
    Thanks
    1
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: <QtDBus/QtDBus> / <dbus/dbus.h>

    Hi,

    Are you able to invoke your method using qdbus or qdbusviewer?

    Now, send messages from root to other users, I don't think this is possible, since for each session, a "dbus-deamon --session" is called, and in man --session says :"Use the standard configuration file for the per-login-session message bus.".

    Hth.

  4. #4
    Join Date
    May 2011
    Posts
    132
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: <QtDBus/QtDBus> / <dbus/dbus.h>

    hmm I think its working different way. I don't send send message to the user session, root writes to system dbus session, and the user reads it from.

Similar Threads

  1. QtDBus Qt Creator
    By sngskunk in forum Qt Programming
    Replies: 2
    Last Post: 22nd August 2019, 09:15
  2. Replies: 0
    Last Post: 9th January 2011, 11:06
  3. Help with QtDBus signals
    By zuck in forum Qt Programming
    Replies: 3
    Last Post: 20th May 2009, 06:33
  4. Qt 4.5.0 win opensource and <dbus/dbus.h>
    By YaK in forum Installation and Deployment
    Replies: 2
    Last Post: 22nd March 2009, 12:06
  5. cannot find -QtDBus
    By rajeshs in forum Qt Programming
    Replies: 1
    Last Post: 1st August 2007, 16:08

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.