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. How to properly connect Slots and Signals over QDBus
Forum Updated to NodeBB v4.3 + New Features

How to properly connect Slots and Signals over QDBus

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 924 Views 1 Watching
  • 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.
  • R Offline
    R Offline
    RyonMS
    wrote on last edited by RyonMS
    #1

    So I have a service that will have multiple clients connecting to it. I want to connect a signal to a slot in such a way that when one client emits a signal, all of the other connected clients will also receive this signal. The client objects are subclassed from the auto-generated proxy that shares the same methods and signals as the server class. I'm assuming inside the client class I will have to connect the signals and slots through a QDBusConnection, but I am unsure of how to do this. If anyone could offer some advice I would greatly appreciate it!

    The Server Object:

    namespace SmartAppMgr
    {
        class SmartAppManager : public QObject
        {
            Q_OBJECT
    
        public:
            SmartAppManager
                (
                QObject* a_parent = NULL
                );
    
            virtual ~SmartAppManager();
    
            Q_SIGNAL void PhoneCallStatusChanged( );
    
            Q_SLOT void onPhoneCallStatusChanged();
    
            bool getPhoneCallStatus();
    
            void setPhoneCallStatus( bool status );
    
        private:
            bool m_phoneCallStatus;
            QDBusConnection mDBusConnection;
        };
    }
    

    The Client Object:

    namespace SmartAppMgr
    {
        class SmartAppManagerClient: public ComSmartAppManagerInterface
        {
            Q_OBJECT
    
        public:
            //! Constructor
            SmartAppManagerClient
                (
                QDBusConnection const& a_connection, 
                QObject* a_parent = 0 
                );
    
            //! Destructor
            virtual ~SmartAppManagerClient();
        };
    }
    

    The service that actually runs everything:

    int main
        (
        int argc,
        char* argv[]
        )
    {
        // Creating the app
        QCoreApplication app( argc, argv );
        QDBusConnection connection = QDBusConnection::systemBus();
    
        SmartAppMgr::SmartAppManager smartAppManager;
        SmartAppManagerAdaptor smartAppManagerAdaptor( &smartAppManager );
    
        if( connection.registerService( SmartAppMgr::sSmartAppManagerBusName ) )
        {
            qDebug() << "\n\nSuccessfully registered the SmartAppManager DBus Service!\n\n";
        }
        else
        {
            qDebug() << "\n\nFailed to register the SmartAppManager DBus serivce!\n\n";
            return -1;
        }
    
        if ( connection.registerObject( SmartAppMgr::sSmartAppManagerObjectPath, &smartAppManager ) )
        {
            qDebug() << "\n\nSuccessfully registered SmartAppManager DBus object!\n\n";
        }
        else
        {
            qDebug() << "\n\nFailed to register the SmartAppManager DBus object!\n\n";
            return -1;
        }
    
        return app.exec();
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Aren't you implementing something like QtRemoteObjects ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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