本文整理汇总了C++中QLocalSocket::deleteLater方法的典型用法代码示例。如果您正苦于以下问题:C++ QLocalSocket::deleteLater方法的具体用法?C++ QLocalSocket::deleteLater怎么用?C++ QLocalSocket::deleteLater使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QLocalSocket
的用法示例。
在下文中一共展示了QLocalSocket::deleteLater方法的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: connectToSimulator
void MobilityConnection::connectToSimulator()
{
// 1. check availability
QLocalSocket *socket = new QLocalSocket;
socket->connectToServer(QLatin1String(SIMULATOR_MOBILITY_SERVERNAME), QLocalSocket::ReadWrite);
if (!socket->waitForConnected(1000)) {
qFatal("Could not connect to mobility server");
socket->deleteLater();
return;
}
mSendSocket = socket;
// 2. Create the local server used for initiating the backchannel.
const qint64 pid = QCoreApplication::applicationPid();
QLocalServer *server = new QLocalServer(this);
if (!server->listen(qt_mobilityServerName(pid)))
qFatal("Can't create local mobility server for this application.");
// 3. Send initial application connect command.
ApplicationConnectCommand command;
ApplicationConnectCommand::Request &request = command.request;
request.applicationPid = pid;
request.applicationName[0] = 0;
request.version = mobilityVersion;
qt_sendAndReceiveApplicationConnect(socket, command);
mSimulatorVersion = command.reply.version;
// We usually want to get the initial state from the simulator directly, probably
// before the event loop is started up. Hence we block until the simulator has established
// the back channel.
if (!server->waitForNewConnection(1000))
qFatal("Simulator didn't establish mobility-backchannel on time");
mReceiveSocket = server->nextPendingConnection();
server->close();
connect(mReceiveSocket, SIGNAL(readyRead()), SLOT(onReadyRead()));
}
示例3: onNewConnection
void Server::onNewConnection()
{
QLocalSocket* socket = m_server->nextPendingConnection();
if (!socket) {
log("No pending client connections!", LogError);
} else if ( socket->state() != QLocalSocket::ConnectedState ) {
log("Client is not connected!", LogError);
socket->deleteLater();
} else {
QScopedPointer<ClientSocket> clientSocket( new ClientSocket(socket) );
const Arguments args = clientSocket->readArguments();
if ( !args.isEmpty() ) {
++m_socketCount;
connect( clientSocket.data(), SIGNAL(destroyed()),
this, SLOT(onSocketClosed()) );
connect( this, SIGNAL(destroyed()),
clientSocket.data(), SLOT(close()) );
connect( this, SIGNAL(destroyed()),
clientSocket.data(), SLOT(deleteAfterDisconnected()) );
emit newConnection( args, clientSocket.take() );
}
}
}
示例4: HandleServerDisconnect
void CLocalSvrCommunication::HandleServerDisconnect( )
{
QLocalSocket* pSocket = qobject_cast< QLocalSocket* >( sender( ) );
pSocket->close( );
pSocket->deleteLater( );
}
示例5: clientLeave
void MainWindow::clientLeave()
{
if(connectedMode=="Tcp socket (QTcpServer)")
{
// Wich client leave
QTcpSocket *socket = qobject_cast<QTcpSocket *>(sender());
if (socket == 0) // If not found
return;
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("Unable to locate client, internal error",10000);
else
{
if(TcpServer.isListening())
ui->statusBarApp->showMessage("The client: "+socket->peerAddress().toString()+" as leave",10000);
tcpSocket[index]->ItemInList->setIcon(QIcon(":/images/list-disconnected.png"));
tcpSocket[index]->isConnected=false;
tcpSocket[index]->tcpSocket=NULL;
socket->deleteLater();
//compression
if(tcpSocket[index]->compression!=NULL)
{
delete tcpSocket[index]->compression;
tcpSocket[index]->compression=NULL;
}
if(tcpSocket[index]->compression!=NULL)
{
delete tcpSocket[index]->compression;
tcpSocket[index]->compression=NULL;
}
}
}
if(connectedMode==COMBOBOXTEXTLOCALSOCK)
{
// Wich client leave
QLocalSocket *socket = qobject_cast<QLocalSocket *>(sender());
if (socket == 0) // If not found
return;
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("Unable to locate client, internal error",10000);
else
{
if(LocalServer.isListening())
ui->statusBarApp->showMessage("Client as leave",10000);
localSocket[index]->ItemInList->setIcon(QIcon(":/images/list-disconnected.png"));
localSocket[index]->isConnected=false;
localSocket[index]->localSocket=NULL;
socket->deleteLater();
}
//compression
if(localSocket[index]->compression!=NULL)
{
delete localSocket[index]->compression;
localSocket[index]->compression=NULL;
}
if(localSocket[index]->compression!=NULL)
{
delete localSocket[index]->compression;
localSocket[index]->compression=NULL;
}
}
}