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. Does Qt Remote Objects can only connect signal and slot defined by sub class?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 4 Posters 1.0k Views
  • 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.
  • MozzieM Offline
    MozzieM Offline
    Mozzie
    wrote on last edited by Mozzie
    #1

    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.

    jsulmJ KroMignonK 2 Replies Last reply
    0
    • MozzieM Mozzie

      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.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      MozzieM 1 Reply Last reply
      0
      • jsulmJ jsulm

        @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?

        MozzieM Offline
        MozzieM Offline
        Mozzie
        wrote on last edited by
        #3

        @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.

        jsulmJ 1 Reply Last reply
        0
        • MozzieM Mozzie

          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.

          KroMignonK Offline
          KroMignonK Offline
          KroMignon
          wrote on last edited by
          #4

          @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 )

          It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

          MozzieM 1 Reply Last reply
          0
          • KroMignonK KroMignon

            @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 )

            MozzieM Offline
            MozzieM Offline
            Mozzie
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            0
            • MozzieM Mozzie

              @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.

              jsulmJ Offline
              jsulmJ Offline
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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.

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              MozzieM 1 Reply Last reply
              0
              • jsulmJ jsulm

                @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.

                MozzieM Offline
                MozzieM Offline
                Mozzie
                wrote on last edited by
                #7

                @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.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mattmart3
                  wrote on last edited by
                  #8

                  Hi everyone, any news on this?

                  I am experiencing the same issue running PyQt5. Following a simple sever-client example (simplified version of this example):

                  Server app:
                  from PyQt5.QtCore import *
                  from PyQt5.QtWidgets import *
                  from PyQt5.QtRemoteObjects import *
                  
                  
                  class Person(QObject):
                      sig_name = pyqtSignal(str)
                  
                      def __init__(self):
                          super().__init__()
                  
                  
                  class Name(Person):
                      def __init__(self):
                          super().__init__()
                          self.startTimer(1000)
                  
                      def timerEvent(self, event):
                          self.sig_name.emit("Test name")
                  
                  
                  class Server(QObject):
                      def __init__(self):
                          super().__init__()
                          self.name = Name()
                          host = QRemoteObjectHost(QUrl("local:server"), self)
                          host.enableRemoting(self.name, "name")
                  
                  
                  app = QCoreApplication([])
                  s = Server()
                  app.exec()
                  
                  Client app:
                  from PyQt5.QtCore import *
                  from PyQt5.QtWidgets import *
                  from PyQt5.QtRemoteObjects import *
                  
                  
                  class Client(QObject):
                      def __init__(self):
                          super().__init__()
                          node = QRemoteObjectNode(self)
                          node.connectToNode(QUrl("local:server"))
                  
                          self.remote_name = node.acquireDynamic("name")
                          self.remote_name.initialized.connect(self.onInitName)
                  
                      def onInitName(self):
                          self.remote_name.sig_name.connect(self.print_info)
                  
                      def print_info(self, x):
                          print("-->:", x)
                  
                  
                  app = QCoreApplication([])
                  c = Client()
                  app.exec()
                  

                  Since the sig_name signal is defined in the super class of the Name class, the client fails on connection:

                      self.remote_name.sig_name.connect(self.print_info)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^
                  AttributeError: 'QRemoteObjectDynamicReplica' object has no attribute 'sig_name'
                  

                  If the signal is instead defined in the Name class it works fine:

                  class Person(QObject):
                      sig_name_super = pyqtSignal(str)
                  
                      def __init__(self):
                          super().__init__()
                  
                  
                  class Name(Person):
                      sig_name = pyqtSignal(str)
                  
                      def __init__(self):
                          super().__init__()
                          self.startTimer(1000)
                          self.sig_name_super.connect(self.sig_name)
                  
                  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