Problem with signals and slots...
-
Since the update to Qt Creator 4.14.0 and 5.15.2, I am getting:
clsMsgSender::tryToConnect is not a signal [clazy-connect-non-signal]
This is now typical on every connect I have, the above is on the line:
QObject::connect(this, &clsMsgSender::tryToConnect ,this, &clsMsgSender::onTryToConnect);
This connect is in the class clsMsgSender, the prototype for this class:
class clsMsgSender : public QObject { Q_OBJECT private: static const quint16 mscuint16ConnectionTO; static mpMsgSenders msmpMsgSenders; static clsMsgSender* mspService; static QThread* mspThread; static qulonglong msulnglngMsgID; bool mblnRun; QTcpSocket* mpsckClient; mqueJSON mqueMsgsOut; QMutex mMutex; quint16 muint16Port; bool blnAnythingToDo(QJsonObject& robjJSON); void push(QJsonObject& robjJSON); public: explicit clsMsgSender(quint16 uint16Port); ~clsMsgSender(); QTcpSocket* pGetClient() { return mpsckClient; } static clsMsgSender* pGetMsgSndr(quint16 uint16Port); static clsMsgSender* pGetService() { return clsMsgSender::mspService; } static QString strGetLocalIP(); void terminate() { mblnRun = false; } quint16 uint16Port() { return muint16Port; } static qulonglong ulnglngGetMsgID() { return clsMsgSender::msulnglngMsgID; } signals: void cannotConnect(); void connected(); void disconnected(); void finished(); void sendJSON(QJsonObject robjJSON); void startService(); void tryToConnect(const QString& crstrHost, const quint16 cint16Port); void write(QJsonObject robjJSON); public slots: void onCreateMsgSndrThrd(); void onErrorOccurred(QAbstractSocket::SocketError sckError); void onSendJSON(QJsonObject robjJSON); void onStartMsgSndrThrd(); void onTryToConnect(const QString& crstrHost, const quint16 cint16Port); void onWrite(QJsonObject robjJSON); void run(); };
Using the debugger I have stepped over an emit of the tryToConnect:
emit tryToConnect(clsMsgSender::strGetLocalIP(), muint16Port);
With a breakpoint in the onTryToConnect slot:
void clsMsgSender::onTryToConnect(const QString& crstrHost, const quint16 cint16Port) { //Get local IP address qdbg() << "Connecting to: " << crstrHost << ":" << cint16Port; //Connect to the Application mpsckClient->connectToHost(crstrHost, cint16Port); if ( mpsckClient->waitForConnected(clsMsgSender::mscuint16ConnectionTO) != true ) { emit cannotConnect(); } }
The breakpoint is on the qdbg() line, it never gets there. I am assuming that this is related to the warning message, but why? This looks like a Qt Creator issue, how can I fix this? In desperation I uninstalled Qt Creator and the Qt folder then re-installed again, it automatically installs Qt Creator 4.14.0 and 5.15.2.
Anyone else using these versions and found the same problems?
-
Hi,
@SPlatten said in Problem with signals and slots...:
Using the debugger I have stepped over an emit of the tryToConnect:
emit mpobjMsgSender->sendJSON(objMsg);With a breakpoint in the onTryToConnect slot:
How is sendJSON related to onTryToConnect ?
By the way, signals should only be emitted from within the classes they are defined in.
-
@SGaist , sorry, my bad, I cut and pasted the wrong code into the post, will correct now. The emit I pasted in is called from the run() which is a slot within the same class.
void clsMsgSender::run() { QTcpSocket::SocketState sckCurState, sckLastState; QJsonObject objJSON; while( mblnRun == true ) { //Sleep to allow a small cap between transmission QThread::usleep(100); sckCurState = mpsckClient->state(); if ( sckLastState != sckCurState ) { sckLastState = sckCurState; qdbg() << mpsckClient->state(); } if ( mpsckClient->state() != QAbstractSocket::ConnectedState ) { if ( mpsckClient->state() != QAbstractSocket::ConnectingState ) { emit tryToConnect(clsMsgSender::strGetLocalIP(), muint16Port); } if ( mpsckClient->state() != QAbstractSocket::ConnectedState ) { continue; } } if ( blnAnythingToDo(objJSON) != true ) { //Nothing to do...yet! continue; } //Look for a module name in the message QJsonObject::iterator itrFound = objJSON.find(clsJSON::mscszMsgType); if ( itrFound != objJSON.end() ) { const QJsonValueRef crobjMsgType = itrFound.value(); QString strMsgType(crobjMsgType.toString()); if ( strMsgType.compare(clsJSON::mscszAck) != 0 ) { //Insert a unique message ID into the message objJSON.insert(clsJSON::mscszMsgID, QString::number(++clsMsgSender::msulnglngMsgID)); //Create entry to monitor status of this message new clsMsgTrkr(this, objJSON); } } //Writes message to socket emit write(objJSON); } }
-
Why do you think that clazy now magically is fixed without any other changes and asking the same question as 4 days ago?
https://forum.qt.io/topic/121934 -
@Christian-Ehrlicher , I was hoping since this is the latest offering, that someone could confirm that this is a Qt issue and not my own?
Is there a way to role back to an earlier version of Qt Creator?