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. Static lib - SIGNAL/SLOT

Static lib - SIGNAL/SLOT

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 3 Posters 1.4k 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.
  • ODБOïO Offline
    ODБOïO Offline
    ODБOï
    wrote on last edited by ODБOï
    #1

    I have created a static lib with qt, a simple QObject derived class.
    Can my static lib be a QObject derived class and have Signal/Slots working ?

    im able to use my lib in another project but cant connect to the signals emited

     CN16K_SFTP sftp; // lib object
    
        sftp.connectToMachine(QString("user@10.81.100.100")); // method call works
        QObject::connect(&sftp,&CN16K_SFTP::errMsgChanged,this,&SftpUser::handleSftpMessage); // handleSftpMessage is never called
    
    
    VRoninV 1 Reply Last reply
    0
    • ODБOïO ODБOï

      I have created a static lib with qt, a simple QObject derived class.
      Can my static lib be a QObject derived class and have Signal/Slots working ?

      im able to use my lib in another project but cant connect to the signals emited

       CN16K_SFTP sftp; // lib object
      
          sftp.connectToMachine(QString("user@10.81.100.100")); // method call works
          QObject::connect(&sftp,&CN16K_SFTP::errMsgChanged,this,&SftpUser::handleSftpMessage); // handleSftpMessage is never called
      
      
      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @LeLev said in Static lib - SIGNAL/SLOT:

      handleSftpMessage is never called

      Since you are allocating sftp on the stack, are you sure it survives long enough to emit the signal in the first place?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      ODБOïO 1 Reply Last reply
      1
      • VRoninV VRonin

        @LeLev said in Static lib - SIGNAL/SLOT:

        handleSftpMessage is never called

        Since you are allocating sftp on the stack, are you sure it survives long enough to emit the signal in the first place?

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on last edited by
        #3

        @VRonin thank you,
        I was creating sftp in the constructor, now i moved it as member variable, but the handler slot is still not called

        1 Reply Last reply
        0
        • VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by VRonin
          #4

          Can you show the entire code? did you remove CN16K_SFTP sftp; // lib object from the constructor?

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          1 Reply Last reply
          0
          • ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by ODБOï
            #5

            @VRonin no i'm not removing it

            #ifndef SFTPUSER_H
            #define SFTPUSER_H
            
            #include <QObject>
            #include "cn16k_sftp.h"
            
            class SftpUser : public QObject
            {
                Q_OBJECT
            public:
                explicit SftpUser(QObject *parent = nullptr);
            signals:
            public slots:
                void handleSftpMessage(QString msg){
                    qDebug()<<"Sftp Messages handeled : " << msg;
                }
            private:
                  CN16K_SFTP m_sftp;
            };
            
            #endif // SFTPUSER_H
            
            
            
            // .cpp
            
            SftpUser::SftpUser(QObject *parent) : QObject(parent)
            {
                m_sftp.connectToMachine(QString("user@10.81.100.100"));
                QObject::connect(&m_sftp,&CN16K_SFTP::errMsgChanged,this,&SftpUser::handleSftpMessage);
            }
            
            
            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              I would move the connect above the call to connectToMachine()

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              ODБOïO 1 Reply Last reply
              3
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #7

                Also, stupid question: are you creating a SftpUser object anywhere?

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  I would move the connect above the call to connectToMachine()

                  ODБOïO Offline
                  ODБOïO Offline
                  ODБOï
                  wrote on last edited by
                  #8

                  @Christian-Ehrlicher Hi, thank you but i don't understand what do you mean,
                  the class i pasted is part of simple qtQuick project, in that project im linking to a static lib i created

                  the CN16K_SFTP m_sftp; is that object. It has a method connectToMachine, when connexion is ok a signal is emited.

                  Now my app just creats a CN16K_SFTP object , uses connectToMachine(), and need to listen the signal, everithing works but signal is not handled.

                  @VRonin yes, because i i said i'm sure that the connexion is etablished and the signal is emitted,
                  i create the SftpUser in my apps main.cpp

                   SftpUser sftp;
                      QQmlApplicationEngine engine;
                      engine.rootContext()->setContextProperty("sftp",&sftp);
                  
                  VRoninV 1 Reply Last reply
                  0
                  • ODБOïO ODБOï

                    @Christian-Ehrlicher Hi, thank you but i don't understand what do you mean,
                    the class i pasted is part of simple qtQuick project, in that project im linking to a static lib i created

                    the CN16K_SFTP m_sftp; is that object. It has a method connectToMachine, when connexion is ok a signal is emited.

                    Now my app just creats a CN16K_SFTP object , uses connectToMachine(), and need to listen the signal, everithing works but signal is not handled.

                    @VRonin yes, because i i said i'm sure that the connexion is etablished and the signal is emitted,
                    i create the SftpUser in my apps main.cpp

                     SftpUser sftp;
                        QQmlApplicationEngine engine;
                        engine.rootContext()->setContextProperty("sftp",&sftp);
                    
                    VRoninV Offline
                    VRoninV Offline
                    VRonin
                    wrote on last edited by
                    #9

                    @LeLev said in Static lib - SIGNAL/SLOT:

                    Hi, thank you but i don't understand what do you mean,

                    He means change

                    m_sftp.connectToMachine(QString("user@10.81.100.100"));
                    QObject::connect(&m_sftp,&CN16K_SFTP::errMsgChanged,this,&SftpUser::handleSftpMessage);
                    

                    to

                    QObject::connect(&m_sftp,&CN16K_SFTP::errMsgChanged,this,&SftpUser::handleSftpMessage);
                    m_sftp.connectToMachine(QString("user@10.81.100.100"));
                    

                    "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                    ~Napoleon Bonaparte

                    On a crusade to banish setIndexWidget() from the holy land of Qt

                    ODБOïO 1 Reply Last reply
                    3
                    • VRoninV VRonin

                      @LeLev said in Static lib - SIGNAL/SLOT:

                      Hi, thank you but i don't understand what do you mean,

                      He means change

                      m_sftp.connectToMachine(QString("user@10.81.100.100"));
                      QObject::connect(&m_sftp,&CN16K_SFTP::errMsgChanged,this,&SftpUser::handleSftpMessage);
                      

                      to

                      QObject::connect(&m_sftp,&CN16K_SFTP::errMsgChanged,this,&SftpUser::handleSftpMessage);
                      m_sftp.connectToMachine(QString("user@10.81.100.100"));
                      
                      ODБOïO Offline
                      ODБOïO Offline
                      ODБOï
                      wrote on last edited by
                      #10

                      @Christian-Ehrlicher , @VRonin that worked ! thank you very much

                      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