本文整理汇总了C++中QLocalSocket::isValid方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocalSocket::isValid方法的具体用法?C++ QLocalSocket::isValid怎么用?C++ QLocalSocket::isValid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket::isValid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: receiveConnection
void QtLocalPeer::receiveConnection()
{
QLocalSocket* socket = server->nextPendingConnection();
if (!socket)
return;
// Why doesn't Qt have a blocking stream that takes care of this shait???
while (socket->bytesAvailable() < static_cast<int>(sizeof(quint32))) {
if (!socket->isValid()) // stale request
return;
socket->waitForReadyRead(1000);
}
QDataStream ds(socket);
QByteArray uMsg;
quint32 remaining;
ds >> remaining;
uMsg.resize(remaining);
int got = 0;
char* uMsgBuf = uMsg.data();
//qDebug() << "RCV: remaining" << remaining;
do {
got = ds.readRawData(uMsgBuf, remaining);
remaining -= got;
uMsgBuf += got;
//qDebug() << "RCV: got" << got << "remaining" << remaining;
} while (remaining && got >= 0 && socket->waitForReadyRead(2000));
//### error check: got<0
if (got < 0) {
qWarning() << "QtLocalPeer: Message reception failed" << socket->errorString();
delete socket;
return;
}
// ### async this
QString message = QString::fromUtf8(uMsg.constData(), uMsg.size());
socket->write(ack, qstrlen(ack));
socket->waitForBytesWritten(1000);
emit messageReceived(message, socket); // ##(might take a long time to return)
}
示例2: slotSetBreakPoint
void DaoxDebugger::slotSetBreakPoint()
{
QLocalSocket *socket = server.nextPendingConnection();
QByteArray sdata;
QTime dieTime= QTime::currentTime().addMSecs(1000);
while( socket->isValid() && sdata.count( '\0' ) < 2 ){
if( QTime::currentTime() > dieTime ) break;
socket->waitForReadyRead();
sdata += socket->readAll();
}
QList<QByteArray> data = sdata.split( '\0' );
if( data.size() < 3 ) return;
QString name = data[0];
int set = data[1].toInt();
int line = data[2].toInt();
if( set ){
if( not breakPoints.contains( name ) ) breakPoints[ name ] = QMap<int,int>();
breakPoints[ name ][ line ] = 1;
}else{
if( breakPoints.contains( name ) ) breakPoints[name].remove( line );
if( breakPoints[name].size() ==0 ) breakPoints.remove( name );
}
}