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@10.81.100.100")); // method call works QObject::connect(&sftp,&CN16K_SFTP::errMsgChanged,this,&SftpUser::handleSftpMessage); // handleSftpMessage is never called
-
@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); }
-
I would move the connect above the call to connectToMachine()
-
@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 createdthe 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.cppSftpUser sftp; QQmlApplicationEngine engine; engine.rootContext()->setContextProperty("sftp",&sftp);
-
@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"));