当前位置: 首页>>代码示例>>C++>>正文


C++ QLocalSocket::readAll方法代码示例

本文整理汇总了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());
		}
	}
}
开发者ID:rgfernandes,项目名称:qtdesktop,代码行数:28,代码来源:SocketListener.cpp

示例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;
    }
}
开发者ID:zealdocs,项目名称:zeal,代码行数:31,代码来源:applicationsingleton.cpp

示例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();
    }
}
开发者ID:alphaonex86,项目名称:debug-devel,代码行数:58,代码来源:mainwindow.cpp

示例4: onReadyRead

void SocketExternalCommunicator::onReadyRead()
{
    QLocalSocket* socket = qobject_cast<QLocalSocket*>(sender());
    QByteArray data;
    data.append(socket->readAll());
    socket->close();

    emit loadFile(QString::fromUtf8(data));
}
开发者ID:Pac72,项目名称:glogg,代码行数:9,代码来源:socketexternalcom.cpp

示例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);
}
开发者ID:Megaxela,项目名称:SASM,代码行数:15,代码来源:singleapplication.cpp

示例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 );
}
开发者ID:Anne081031,项目名称:ParkCode,代码行数:13,代码来源:localsvrcommunication.cpp

示例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();
}
开发者ID:DOOMer,项目名称:screengrab,代码行数:13,代码来源:singleapp.cpp

示例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();
        }
    }
}
开发者ID:ccrma,项目名称:miniAudicle,代码行数:50,代码来源:mASocketManager.cpp

示例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();
}
开发者ID:0x414c,项目名称:SpeedCrunch,代码行数:15,代码来源:application.cpp

示例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;
}
开发者ID:monero-project,项目名称:monero-core,代码行数:15,代码来源:ipc.cpp

示例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);
  }
}
开发者ID:HenryHu,项目名称:lumina,代码行数:16,代码来源:LuminaSingleApplication.cpp

示例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;
        }
    }
}
开发者ID:KDE,项目名称:sink,代码行数:19,代码来源:listener.cpp

示例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);
	}	
}
开发者ID:diepdtnse03145,项目名称:Qt-IPC-Server-Client,代码行数:20,代码来源:qserver.cpp

示例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;
        }
    }
}
开发者ID:aseigo,项目名称:toynadi,代码行数:20,代码来源:listener.cpp

示例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;
}
开发者ID:13W,项目名称:icq-desktop,代码行数:41,代码来源:local_peer.cpp


注:本文中的QLocalSocket::readAll方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。