本文整理汇总了C++中QLocalSocket::readAll方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocalSocket::readAll方法的具体用法?C++ QLocalSocket::readAll怎么用?C++ QLocalSocket::readAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket::readAll方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onNewConnection
void SocketListener::onNewConnection() {
JUFFENTRY;
QLocalSocket* socket = server_->nextPendingConnection();
if ( !socket->waitForReadyRead(1000) ) {
qDebug() << "Couldn't read data:" << socket->errorString();
return;
}
QByteArray data = socket->readAll();
JUFFDEBUG(QString::fromLocal8Bit(data));
if ( data.isEmpty() ) {
return;
}
QStringList list = QString::fromLocal8Bit(data).split(";");
foreach (QString arg, list) {
if ( arg[0] == '-' ) {
if ( arg.compare("--newfile") == 0 ) {
emit newFileRequested();
}
}
else {
if ( !arg.isEmpty() )
emit fileRecieved(QFileInfo(arg).absoluteFilePath());
}
}
}
示例2: setupPrimary
void ApplicationSingleton::setupPrimary()
{
m_primaryPid = QCoreApplication::applicationPid();
qCInfo(log, "Starting as a primary instance. (PID: %lld)", m_primaryPid);
m_sharedMemory->lock();
auto sd = static_cast<SharedData *>(m_sharedMemory->data());
sd->primaryPid = m_primaryPid;
m_sharedMemory->unlock();
QLocalServer::removeServer(m_id);
m_localServer = new QLocalServer(this);
m_localServer->setSocketOptions(QLocalServer::UserAccessOption);
connect(m_localServer, &QLocalServer::newConnection, this, [this] {
QLocalSocket *socket = m_localServer->nextPendingConnection();
connect(socket, &QLocalSocket::readyRead, this, [this, socket] {
QByteArray data = socket->readAll();
emit messageReceived(data);
socket->deleteLater();
});
});
if (!m_localServer->listen(m_id)) {
qCWarning(log) << "Cannot start the local service:"
<< m_localServer->errorString();
return;
}
}
示例3: newData
void MainWindow::newData()
{
if(connectedMode=="Tcp socket (QTcpServer)") // if connection is on tcp socket mode
{
QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
int index=-1;
for (int i = 0; i < tcpSocket.size(); ++i) {
if(tcpSocket.at(i)->tcpSocket==socket)
index=i;
}
if(index==-1)
{
ui->statusBarApp->showMessage("Internal error at newData()",10000);
return;
}
QByteArray block=socket->readAll();
//load in hexa if needed and append or update the text
if(ui->comboBoxModeAppend->currentText()=="Update")
tcpSocket[index]->IncomingData.clear();
QByteArray raw_data;
if(ui->compressedStream->isChecked())
raw_data=tcpSocket[index]->compression->decompressData(block);
else
raw_data=block;
//load in hexa if needed and append or update the text
tcpSocket[index]->IncomingData.append(raw_data);
updateCurrentData();
}
if(connectedMode==COMBOBOXTEXTLOCALSOCK) // if connection is on local socket mode
{
QLocalSocket *socket = qobject_cast<QLocalSocket *>(sender());
int index=-1;
for (int i = 0; i < localSocket.size(); ++i) {
if(localSocket.at(i)->localSocket==socket)
index=i;
}
if(index==-1)
{
ui->statusBarApp->showMessage("Internal error at newData()",10000);
return;
}
QByteArray block=socket->readAll();
//load in hexa if needed and append or update the text
if(ui->comboBoxModeAppend->currentText()=="Update")
localSocket[index]->IncomingData.clear();
QByteArray raw_data;
if(ui->compressedStream->isChecked())
raw_data=tcpSocket[index]->compression->decompressData(block);
else
raw_data=block;
localSocket[index]->IncomingData.append(raw_data);
updateCurrentData();
}
}
示例4: onReadyRead
void SocketExternalCommunicator::onReadyRead()
{
QLocalSocket* socket = qobject_cast<QLocalSocket*>(sender());
QByteArray data;
data.append(socket->readAll());
socket->close();
emit loadFile(QString::fromUtf8(data));
}
示例5: slotConnectionEstablished
/**
* @brief Executed when the showUp command is sent to LocalServer
*/
void SingleApplication::slotConnectionEstablished()
{
QLocalSocket *socket = d_ptr->server->nextPendingConnection();
QByteArray data;
if (socket->waitForReadyRead())
data = socket->readAll();
socket->close();
delete socket;
emit otherInstanceDataReceived(data);
}
示例6: GetData
void CLocalSvrCommunication::GetData( )
{
QLocalSocket* pSocket = qobject_cast< QLocalSocket* >( sender( ) );
quint64 nDataSize = pSocket->bytesAvailable( );
if ( 0 == nDataSize ) {
return;
}
QByteArray byData = pSocket->readAll( );
QString strMsg( byData );
emit NotifyMsg( strMsg );
}
示例7: receiveMessage
void SingleApp::receiveMessage()
{
QLocalSocket *localSocket = localServer->nextPendingConnection();
if (!localSocket->waitForReadyRead(timeout))
{
qDebug("%s", qPrintable(localSocket->errorString().toLatin1()));
return;
}
QByteArray byteArray = localSocket->readAll();
QString message = QString::fromUtf8(byteArray.constData());
emit messageReceived(message);
localSocket->disconnectFromServer();
}
示例8: newConnection
void mASocketManager::newConnection()
{
//fprintf(stderr, "[miniAudicle]: received connection from remote\n");
//fflush(stderr);
QLocalSocket * socket = m_server->nextPendingConnection();
QByteArray data;
QString path;
int timeouts = 0;
while(timeouts < MAX_TIMEOUTS)
{
if(socket->bytesAvailable() <= 0 && !socket->waitForReadyRead(MAX_TIMEOUT_MS/MAX_TIMEOUTS))
timeouts++;
else
{
QByteArray bytes = socket->readAll();
data.append(bytes);
bytes.append('\0');
//fprintf(stderr, "[miniAudicle]: received data '%s'\n", bytes.constData());
// check for line ending
if(data.at(data.length()-1) == '\n')
{
path = QString(data);
// remove trailing \n
path.remove(path.length()-1, 1);
socket->close();
socket = NULL;
break;
}
}
}
if(path.length())
{
if(QFileInfo(path).exists())
{
//fprintf(stderr, "[miniAudicle]: received path '%s' from remote\n", path.toUtf8().constData());
//fflush(stderr);
m_mainWindow->openFile(path);
m_mainWindow->activateWindow();
m_mainWindow->raise();
m_mainWindow->show();
}
}
}
示例9: receiveMessage
void Application::receiveMessage()
{
QLocalSocket *localSocket = d_ptr->localServer.nextPendingConnection();
if (!localSocket->waitForReadyRead(GUI_APPLICATION_LOCAL_SOCKET_TIMEOUT))
return;
QByteArray byteArray = localSocket->readAll();
const QString message = QString::fromUtf8(byteArray.constData());
if (message == "raise")
emit raiseRequested();
localSocket->disconnectFromServer();
}
示例10: handleConnection
void IPC::handleConnection(){
QLocalSocket *clientConnection = this->m_server->nextPendingConnection();
connect(clientConnection, &QLocalSocket::disconnected,
clientConnection, &QLocalSocket::deleteLater);
clientConnection->waitForReadyRead(2);
QByteArray cmdArray = clientConnection->readAll();
QString cmdString = QTextCodec::codecForMib(106)->toUnicode(cmdArray); // UTF-8
qDebug() << cmdString;
this->parseCommand(cmdString);
clientConnection->close();
delete clientConnection;
}
示例11: newInputsAvailable
//New messages detected
void LSingleApplication::newInputsAvailable(){
while(lserver->hasPendingConnections()){
QLocalSocket *sock = lserver->nextPendingConnection();
QByteArray bytes;
sock->waitForReadyRead();
while(sock->bytesAvailable() > 0){ //if(sock->waitForReadyRead()){
//qDebug() << "Info Available";
bytes.append( sock->readAll() );
}
sock->disconnectFromServer();
QStringList inputs = QString::fromLocal8Bit(bytes).split("::::");
//qDebug() << " - New Inputs Detected:" << inputs;
emit InputsAvailable(inputs);
}
}
示例12: readFromSocket
void Listener::readFromSocket()
{
QLocalSocket *socket = qobject_cast<QLocalSocket *>(sender());
if (!socket) {
return;
}
log("Reading from socket...");
for (Client &client: m_connections) {
if (client.socket == socket) {
client.commandBuffer += socket->readAll();
if (processClientBuffer(client) && !m_clientBufferProcessesTimer->isActive()) {
// we have more client buffers to handle
m_clientBufferProcessesTimer->start();
}
break;
}
}
}
示例13: readSocket
void QServer::readSocket()
{
//Pointer to the signal sender
QLocalSocket * socket = (QLocalSocket*)sender();
//Read all data on the socket & store it on a QByteArray
QByteArray block = socket->readAll();
//Data stream to easy read all data
QDataStream in(&block, QIODevice::ReadOnly);
in.setVersion(QDataStream::Qt_5_4);
while (!in.atEnd()) //loop needed cause some messages can come on a single packet
{
QString receiveString;
in >> receiveString;
receiveString.prepend(QString("%1 :: ").arg(socket->socketDescriptor()));
emit sms(receiveString);
}
}
示例14: readFromSocket
void Listener::readFromSocket()
{
QLocalSocket *socket = qobject_cast<QLocalSocket *>(sender());
if (!socket) {
return;
}
Console::main()->log("Reading from socket...");
for (Client &client: m_connections) {
if (client.socket == socket) {
Console::main()->log(QString(" Client: %1").arg(client.name));
client.commandBuffer += socket->readAll();
// FIXME: schedule these rather than process them all at once
// right now this can lead to starvation of clients due to
// one overly active client
while (processClientBuffer(client)) {}
break;
}
}
}
示例15: get_hwnd_and_activate
unsigned int LocalPeer::get_hwnd_and_activate()
{
unsigned int hwnd = 0;
#ifdef _WIN32
QLocalSocket socket;
bool connOk = false;
int timeout = 5000;
for(int i = 0; i < 2; i++)
{
socket.connectToServer(socket_name_);
connOk = socket.waitForConnected(timeout/2);
if (connOk || i)
break;
int ms = 250;
Sleep(DWORD(ms));
}
if (!connOk)
return false;
QByteArray uMsg((QString(crossprocess_message_get_hwnd_activate)).toUtf8());
QDataStream ds(&socket);
ds.writeBytes(uMsg.constData(), uMsg.size());
if (socket.waitForBytesWritten(timeout))
{
if (socket.waitForReadyRead(timeout))
{
QByteArray data_read = socket.readAll();
if (data_read.size() == sizeof(hwnd))
{
hwnd = *(unsigned int*) data_read.data();
}
}
}
#endif _WIN32
return hwnd;
}