Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Does Qt Remote Objects can only connect signal and slot defined by sub class?



  • Hi,

    Recently, I am using Qt Remote Objects, I want to implement different server with same API, so I write a base class which defined some signal and slots, and then implement it in the server application.
    for example:

    class A : public QObject {
        Q_OBJECT
    signals:
    	void testSignal();
    
    public slots:
    	void parentSlot() {}
    	virtual void testSlot() = 0;
    
    }
    
    class B : public A {
    	Q_OBJECT
    
    public slots:
    	virtual void testSlot() override {
                emit testSignal();
    	}
    }
    
    B* server = new B(this);
    host->enableRemoting(server, m_serverName)
    

    I found I can connect testSlot but I can not connect testSignal and parentSlot from client.

    such as:

    
    auto interface = node->acquireDynamic(m_serverName);
    qDebug() << "interface" << interface;
    if (interface) {
    	connect(interface, &QRemoteObjectDynamicReplica::initialized, this, [this, interface](){
    		connect(this, SIGNAL(testSlotReady()), interface, SLOT(testSlot()));
    		connect(this, SIGNAL(testSlotReady()), interface, SLOT(parentSlot()));
    		connect(interface, SIGNAL(testSignal()), interface, SLOT(onTestSignal()));
    		
    	});
    	connect(interface, &QRemoteObjectDynamicReplica::stateChanged,
    			this, [this](QRemoteObjectReplica::State state, QRemoteObjectReplica::State oldState){
    		qDebug() << "state" << state << oldState;
    	});
    
    
    }
    

    It said: QObject::connect: No such slot ... and QObject::connect: No such signal ... when the application is running.
    Does Qt Remote Objects can only connect signal and slot defined by sub class? Why or is there any thing I'm using is not correct?

    Thank you.


  • Lifetime Qt Champion

    @Mozzie said in Does Qt Remote Objects can only connect signal and slot defined by sub class?:

    but I can not connect testSignal and parentSlot from client

    Where in the code you posted are you connecting them?
    And what happens if you try to do so?



  • @jsulm
    Hi,
    I am using dynamic replica of the Qt Remote Objects, the conncting code is

    	connect(interface, &QRemoteObjectDynamicReplica::initialized, this, [this, interface](){
    		connect(this, SIGNAL(testSlotReady()), interface, SLOT(testSlot()));
    		connect(this, SIGNAL(testSlotReady()), interface, SLOT(parentSlot()));
    		connect(interface, SIGNAL(testSignal()), interface, SLOT(onTestSignal()));
    		
    	});
    

    It said: QObject::connect: No such slot ::parentSlot and QObject::connect: No such signal ::testSignal when the application is running.
    the connect(this, SIGNAL(testSlotReady()), interface, SLOT(testSlot())); is working, but the other two is not working unless I move parentSlot from class A to Class B, then the connect(this, SIGNAL(testSlotReady()), interface, SLOT(parentSlot())); will work.



  • @Mozzie said in Does Qt Remote Objects can only connect signal and slot defined by sub class?:

    Recently, I am using Qt Remote Objects, I want to implement different server with same API, so I write a base class which defined some signal and slots, and then implement it in the server application.

    I don't know if you post the complet header code, if so, then please add Q_OBJECT to the class definition!

    class A : public QObject {
        Q_OBJECT
    ...
    };
    
    class B : public A {
        Q_OBJECT
    ...
    };
    

    Q_OBJECT is mandatory is you want to add signals/slots to a class (cf. https://doc.qt.io/qt-5/qobject.html#details or )



  • @KroMignon

    Thank you. I did not post the complet header code, it is just a simplify version of my code, this might not be the reason.


  • Lifetime Qt Champion

    @Mozzie Please try with Qt5 connect syntax:

    connect(interface, &BASE_CLASS::testSignal, interface, &INTERFACE_CLASS::onTestSignal);
    

    You should not use the old connect syntax anymore.



  • @jsulm

    When use acquireDynamic, It means I dont have the interface header file in the server application, I only know the signals and slots of it, and the QRemoteObjectDynamicReplica *QRemoteObjectNode::acquireDynamic(const QString &name) function return a replica, so I can not use Qt5 connect syntax. and the child slot is working, so I think this migth not be a problem.


Log in to reply