本文整理汇总了C++中QLocalSocket::canReadLine方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocalSocket::canReadLine方法的具体用法?C++ QLocalSocket::canReadLine怎么用?C++ QLocalSocket::canReadLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket::canReadLine方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: slotHandleUniqueApplicationConnection
void ApplicationCore::slotHandleUniqueApplicationConnection()
{
QLocalSocket *socket = m_uniqueApplicationServer.nextPendingConnection();
connect(socket, &QLocalSocket::readyRead, socket, [this, socket](){
if (!socket->canReadLine())
return;
while (socket->canReadLine()) {
const QByteArray data = socket->readLine().trimmed();
if (data.startsWith(StartTaskCommand)) {
bool ok = true;
const TaskId id = data.mid(StartTaskCommand.length()).toInt(&ok);
if (ok) {
m_timeTracker.slotStartEvent(id);
} else {
qWarning() << "Received invalid argument:" << data;
}
} else if (data.startsWith(RaiseWindowCommand)) {
// nothing to do, see below
}
}
socket->deleteLater();
showMainWindow(ApplicationCore::ShowMode::ShowAndRaise);
});
}
示例2: parser
void
PlayerListener::onDataReady()
{
QLocalSocket* socket = qobject_cast<QLocalSocket*>(sender());
if (!socket) return;
while (socket->canReadLine())
{
QString const line = QString::fromUtf8( socket->readLine() );
try
{
PlayerCommandParser parser( line );
QString const id = parser.playerId();
PlayerConnection* connection = 0;
if (!m_connections.contains( id )) {
connection = m_connections[id] = new PlayerConnection( parser.playerId(), parser.playerName() );
emit newConnection( connection );
}
else
connection = m_connections[id];
switch (parser.command())
{
case CommandBootstrap:
emit bootstrapCompleted( parser.playerId() );
break;
case CommandTerm:
delete connection;
m_connections.remove( parser.playerId() );
break;
default:
connection->handleCommand( parser.command(), parser.track() );
break;
}
socket->write( "OK\n" );
}
catch (std::invalid_argument& e)
{
qWarning() << e.what();
QString s = "ERROR: " + QString::fromStdString(e.what()) + "\n";
socket->write( s.toUtf8() );
}
}
}
示例3: slotReadSocket
void SocketApi::slotReadSocket()
{
QLocalSocket* socket = qobject_cast<QLocalSocket*>(sender());
Q_ASSERT(socket);
while(socket->canReadLine()) {
QString line = QString::fromUtf8(socket->readLine()).trimmed();
QString command = line.split(":").first();
QString function = QString(QLatin1String("command_")).append(command);
QString functionWithArguments = function + QLatin1String("(QString,QLocalSocket*)");
int indexOfMethod = this->metaObject()->indexOfMethod(functionWithArguments.toAscii());
QString argument = line.remove(0, command.length()+1).trimmed();
if(indexOfMethod != -1) {
QMetaObject::invokeMethod(this, function.toAscii(), Q_ARG(QString, argument), Q_ARG(QLocalSocket*, socket));
} else {
示例4: receiveMessage
void QtLocalPeer::receiveMessage()
{
QLocalSocket *socket = (QLocalSocket*)(sender());
QString msg;
while (socket->bytesAvailable() > 0) {
if (socket->canReadLine()) {
msg = socket->readLine();
} else {
msg = socket->readAll();
}
// qDebug()<<"local peer reciveing data:"<<msg<<socket->bytesAvailable();
if (this->isClient()) {
emit messageReceived(msg);
} else {
int client_id = this->clients.value(socket);
emit messageReceived(msg, client_id);
}
}
}
示例5: newConnection
void RKGraphicsDeviceFrontendTransmitter::newConnection () {
RK_TRACE (GRAPHICS_DEVICE);
RK_ASSERT (!connection);
QLocalSocket *con = local_server->nextPendingConnection ();
local_server->close ();
// handshake
QString token = RKFrontendTransmitter::instance ()->connectionToken ();
if (!con->canReadLine ()) con->waitForReadyRead (1000);
QString token_c = QString::fromLocal8Bit (con->readLine ());
token_c.chop (1);
if (token_c != token) {
KMessageBox::detailedError (0, QString ("<p>%1</p>").arg (i18n ("There has been an error while trying to connect the on-screen graphics backend. This means, on-screen graphics using the RKWard device will not work in this session.")), i18n ("Expected connection token %1, but read connection token %2").arg (token).arg (token_c), i18n ("Error while connection graphics backend"));
con->close ();
return;
}
connection = con;
streamer.setIODevice (con);
connect (connection, SIGNAL (readyRead ()), this, SLOT (newData ()));
newData (); // might already be available
}