Important: Please read the Qt Code of Conduct -

Static lib - SIGNAL/SLOT

  • 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@")); // method call works
        QObject::connect(&sftp,&CN16K_SFTP::errMsgChanged,this,&SftpUser::handleSftpMessage); // handleSftpMessage is never called

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

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

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

  • @VRonin no i'm not removing it

    #ifndef SFTPUSER_H
    #define SFTPUSER_H
    #include <QObject>
    #include "cn16k_sftp.h"
    class SftpUser : public QObject
        explicit SftpUser(QObject *parent = nullptr);
    public slots:
        void handleSftpMessage(QString msg){
            qDebug()<<"Sftp Messages handeled : " << msg;
          CN16K_SFTP m_sftp;
    #endif // SFTPUSER_H
    // .cpp
    SftpUser::SftpUser(QObject *parent) : QObject(parent)

  • Lifetime Qt Champion

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

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

  • @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;

  • @LeLev said in Static lib - SIGNAL/SLOT:

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

    He means change




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

Log in to reply