Hello,
EDIT: See 1st reply for likely solution.
I've seen this question get asked a lot but haven't found much of an answer beyond 'something is wrong with your sockets'. I've found this--thanks caduel--which says that 26 is likely an invalid file descriptor. How would an invalid descriptor come to be sent to a QSocketNotifier method? The socket in question is a QLocalSocket (one of two write sockets), and here is the code I use to send a message:
void MyClass::WriteToLog(const string& msg, MY_MSG_TYPE type)
{
out << quint16
(0) << quint8
(type
) <<
QString(msg.
c_str());
int num_bytes = qb.size() - sizeof(quint16); //Subtract four because in reading the
//size information, the two bytes containing it are removed from the stream
// Also sizeof(MY_MSG_TYPE) == 8
out.device()->seek(0);
out << quint16(num_bytes);
my_socket->write(qb);
my_socket->flush();
}
void MyClass::WriteToLog(const string& msg, MY_MSG_TYPE type)
{
QByteArray qb;
QDataStream out(&qb,QIODevice::WriteOnly);
out << quint16(0) << quint8(type) << QString(msg.c_str());
int num_bytes = qb.size() - sizeof(quint16); //Subtract four because in reading the
//size information, the two bytes containing it are removed from the stream
// Also sizeof(MY_MSG_TYPE) == 8
out.device()->seek(0);
out << quint16(num_bytes);
my_socket->write(qb);
my_socket->flush();
}
To copy to clipboard, switch view to plain text mode
This seems to happen more frequently the more data I send through this socket, but I don't really send that much, maybe several hundred bytes every vertical refresh (60Hz), or ~50KB/sec tops to get this.
I looked at the QSocketNotifier code and what I saw there confused me a little bit--
const char *name)
{
setObjectName
(QString::fromAscii(name
));
if (socket < 0)
qWarning("QSocketNotifier: Invalid socket specified");
sockfd = socket;
sntype = type;
snenabled = true;
...
}
QSocketNotifier::QSocketNotifier(int socket, Type type, QObject *parent,
const char *name)
: QObject(parent)
{
setObjectName(QString::fromAscii(name));
if (socket < 0)
qWarning("QSocketNotifier: Invalid socket specified");
sockfd = socket;
sntype = type;
snenabled = true;
...
}
To copy to clipboard, switch view to plain text mode
It doesn't return the complete error message, and in the message I do get, the socket descriptor is always >0, e.g. 24 or 26.
Lastly, this crash is happening in a process launched from the one I launch using QtCreator, so I don't get any debugging output beyond what's in the subject line.
Can anybody help me with this? Thank you--
Best,
Matt
Bookmarks