本文整理汇总了C++中QLocalSocket::disconnectFromServer方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocalSocket::disconnectFromServer方法的具体用法?C++ QLocalSocket::disconnectFromServer怎么用?C++ QLocalSocket::disconnectFromServer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket::disconnectFromServer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sendMessages
bool KNSingletonApplication::sendMessages(const QString &uniqueKey,
const QStringList &messages)
{
//Create sender client.
QLocalSocket client;
//Link to the server which is listening to the unique key.
client.connectToServer(uniqueKey, QIODevice::WriteOnly);
//If connecting failed, return false.
if(!client.waitForConnected(TimeoutLimit))
{
qDebug("Cannot connect to the local server.");
//Disconnect from the server.
client.disconnectFromServer();
return false;
}
//Generate the message data.
QByteArray messageData;
QDataStream dataWriter(&messageData, QIODevice::WriteOnly);
dataWriter << messages;
//Send the data to local server.
client.write(messageData);
//Check sending status.
if(!client.waitForBytesWritten(TimeoutLimit))
{
qDebug("Send arguments failed.");
client.disconnectFromServer();
return false;
}
//Send the arguments success.
client.disconnectFromServer();
return true;
}
示例2: QLocalSocket
bool N810GpsPlugin::sendToGpsDriverCtrl(QString cmd)
{
QLocalSocket *gpsCtrlSocket;
gpsCtrlSocket = new QLocalSocket(this);
QByteArray socketPath = ( "/var/lib/gps/gps_driver_ctrl");
gpsCtrlSocket->connectToServer(socketPath.data());
if(gpsCtrlSocket->waitForConnected()) {
qLog(Hardware)<< __PRETTY_FUNCTION__ << "connected" << cmd;
QByteArray data;
data.append(cmd);
data.append("\n");
gpsCtrlSocket->write(data);
gpsCtrlSocket->flush();
gpsCtrlSocket->disconnectFromServer();
return true;
} else {
qLog(Hardware) << __PRETTY_FUNCTION__ << "Could not connect to socket" << gpsCtrlSocket;
}
return false;
}
示例3: qt_connectToServer
void qt_connectToServer()
{
if (!qt_initialized)
return;
// Determine to which server we should connect
QString server = qt_localServerName;
if (!qt_optionWidget.isEmpty())
server = qt_optionWidget;
// Check if we are already connected
if (qt_socket.serverName() == server)
return;
// Disconnect
if (qt_socket.state() == QLocalSocket::ConnectedState)
{
qt_socket.disconnectFromServer();
qt_socket.waitForDisconnected(1000);
}
// Connect to server, or local server if not available.
qt_socket.connectToServer(server);
if (!qt_socket.waitForConnected(3000))
while (qt_socket.state() != QLocalSocket::ConnectedState)
qt_socket.connectToServer(qt_localServerName);
}
示例4: saveCommand
// Process incoming IPC command. First check if monero-wallet-gui is
// already running. If it is, send it to that instance instead, if not,
// queue the command for later use inside our QML engine. Returns true
// when queued, false if sent to another instance, at which point we can
// kill the current process.
bool IPC::saveCommand(QString cmdString){
qDebug() << QString("saveCommand called: %1").arg(cmdString);
QLocalSocket ls;
QByteArray buffer;
buffer = buffer.append(cmdString);
QString socketFilePath = this->socketFile().filePath();
ls.connectToServer(socketFilePath, QIODevice::WriteOnly);
if(ls.waitForConnected(1000)){
ls.write(buffer);
if (!ls.waitForBytesWritten(1000)){
qDebug() << QString("Could not send command \"%1\" over IPC %2: \"%3\"").arg(cmdString, socketFilePath, ls.errorString());
return false;
}
qDebug() << QString("Sent command \"%1\" over IPC \"%2\"").arg(cmdString, socketFilePath);
return false;
}
if(ls.isOpen())
ls.disconnectFromServer();
// Queue for later
this->SetQueuedCmd(cmdString);
return true;
}
示例5: ipcSendCommandLine
//
// Sending to the server is done synchronously, at startup.
// If the server isn't already running, startup continues,
// and the items in savedPaymentRequest will be handled
// when uiReady() is called.
//
bool PaymentServer::ipcSendCommandLine()
{
bool fResult = false;
for (const QString& r : savedPaymentRequests)
{
QLocalSocket* socket = new QLocalSocket();
socket->connectToServer(ipcServerName(), QIODevice::WriteOnly);
if (!socket->waitForConnected(BITCOIN_IPC_CONNECT_TIMEOUT))
{
delete socket;
socket = nullptr;
return false;
}
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_0);
out << r;
out.device()->seek(0);
socket->write(block);
socket->flush();
socket->waitForBytesWritten(BITCOIN_IPC_CONNECT_TIMEOUT);
socket->disconnectFromServer();
delete socket;
socket = nullptr;
fResult = true;
}
return fResult;
}
示例6: sendQuit
bool LH_QtPlugin_WebKit::sendQuit()
{
QLocalSocket sock;
sock.connectToServer("LCDHost_WebKitServer");
if( !sock.waitForConnected(100) ) return false;
WebKitCommand('Q').write(&sock);
sock.waitForBytesWritten(100);
sock.disconnectFromServer();
return true;
}
示例7:
bool
socket_test_connect(QString server, int timeout)
{
QLocalSocket sock;
sock.connectToServer(server);
if (!sock.waitForConnected(timeout)) {
return false;
}
sock.disconnectFromServer();
return true;
}
示例8: tryConnect
bool DebugEngine::tryConnect()
{
QLocalSocket localSocket;
localSocket.connectToServer(ExtraSocket::pathSocket(ULTRACOPIER_SOCKETNAME),QIODevice::WriteOnly|QIODevice::Unbuffered);
if(localSocket.waitForConnected(1000))
{
localSocket.disconnectFromServer();
return true;
}
else
return false;
}
示例9: tryConnect
bool DebugEngine::tryConnect()
{
ULTRACOPIER_DEBUGCONSOLE(DebugLevel_custom_Notice,"start");
QLocalSocket localSocket;
localSocket.connectToServer(ExtraSocket::pathSocket(ULTRACOPIER_SOCKETNAME),QIODevice::WriteOnly|QIODevice::Unbuffered);
if(localSocket.waitForConnected(1000))
{
localSocket.disconnectFromServer();
return true;
}
else
return false;
}
示例10: 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();
}
示例11: isServerRun
int HLocalServer::isServerRun(const QString &servername)
{
// 用一个localsocket去连一下,如果能连上就说明有一个在运行了
QLocalSocket ls;
ls.connectToServer(servername);
if (ls.waitForConnected(1000))
{
ls.disconnectFromServer();
ls.close();
return 1;
}
return 0;
}
示例12: 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();
}
示例13: 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);
}
}
示例14: newConnection
void DebconfFrontendSocket::newConnection()
{
qCDebug(DEBCONF);
if (m_socket) {
QLocalSocket *socket = m_server->nextPendingConnection();
socket->disconnectFromServer();
socket->deleteLater();
return;
}
m_socket = m_server->nextPendingConnection();
if (m_socket) {
connect(m_socket, SIGNAL(readyRead()), this, SLOT(process()));
connect(m_socket, SIGNAL(disconnected()), this, SLOT(disconnected()));
}
}
示例15: clientConnected
void MegaSyncLogger::clientConnected()
{
disconnected();
while (megaServer->hasPendingConnections())
{
QLocalSocket *socket = megaServer->nextPendingConnection();
socket->disconnectFromServer();
socket->deleteLater();
}
client = new QLocalSocket();
connect(client, SIGNAL(disconnected()), this, SLOT(disconnected()));
connect(client, SIGNAL(error(QLocalSocket::LocalSocketError)), SLOT(disconnected()));
client->connectToServer(MEGA_LOGGER);
connected = true;
}