Solved QTcpSocket, writing data error
-
I'm using QTcpSocket, I've written a class derived from QTcpSocket:
class clsModHelper : public QTcpSocket { Q_OBJECT ... };
In have a routine that sends a JSON packet:
void clsModHelper::sendJSON(QJsonObject& objJSON) { if ( isOpen() != true ) { return; } //Associate this TCP socket with the output data stream QByteArray arybytMsg; QDataStream dsOut(&arybytMsg, QIODevice::WriteOnly); //dsOut.setDevice(this); dsOut.setVersion(clsJSON::mscintQtVersion); //Send message to data stream dsOut << QJsonDocument(objJSON).toJson(QJsonDocument::Compact); //Write message qint64 int64Written = write(arybytMsg); qdbg() << "sendJSON: " << int64Written; }
I can see that 54 is returned by the call to write. However I have connected to various signals:
QObject::connect(pParent, SIGNAL(aboutToQuit()), this, SLOT(onExitModule())); QObject::connect(this, SIGNAL(connected()), this, SLOT(onConnected())); QObject::connect(this, SIGNAL(connected()), this, SLOT(onSendModuleStartupMsg())); QObject::connect(this, SIGNAL(connected()), this, SLOT(onStartHeartbeat())); QObject::connect(this, SIGNAL(disconnected()), this, SLOT(onDisconnected())); QObject::connect(this, &QAbstractSocket::errorOccurred, this, &clsModHelper::onErrorOccurred); QObject::connect(this, &QIODevice::readyRead, this, &clsModHelper::onDataIn); QObject::connect(this, SIGNAL(bytesWritten(qint64)), this, SLOT(onBytesWritten(qint64))); QObject::connect(this, &clsModHelper::terminateModule, this, &clsModHelper::onExitModule);
I get an error when writing and the error code is 1, according to:
https://gist.github.com/gabrielfalcao/4216897This means Operation not permitted...what could explain this?
-
@SPlatten I don't know what that file is about. If you're talking about QAbstractSocket::errorOccurred then the correct documentation is https://doc.qt.io/qt-5/qabstractsocket.html#SocketError-enum
-
@SPlatten said in QTcpSocket, writing data error:
I get an error
Via QAbstractSocket::errorOccurred? If so then 1 means QAbstractSocket::RemoteHostClosedError
-
@jsulm , ah...is the list I posted in the link for a different set of errors?
-
@SPlatten I don't know what that file is about. If you're talking about QAbstractSocket::errorOccurred then the correct documentation is https://doc.qt.io/qt-5/qabstractsocket.html#SocketError-enum
-
@jsulm , thank you.