//QLocalSocket namedPipe, QByteArray byteArray and QTimer timer are available as member variables.
QString pipeName
="Get it from Registry";
connect(&namedPipe,SIGNAL(connected()),this,SLOT(sloConnected()));
connect(&namedPipe,SIGNAL(error(QLocalSocket::LocalSocketError)),this,SLOT(sloConnectionError()));
namedPipe.
connectToServer(pipeName,
QIODevice::ReadOnly);
void ClassName::sloConnected()
{
connect(&timer,SIGNAL(timeout()),this,SLOT(sloProcess()));
timer.start(200); //i need to update my clients with the changed/unchanged data at regular intervals
}
void ClassName::sloProcess()
{
if(namedPipe.bytesAvailable())
byteArray=namedPipe.readAll();
//deal with byteArray. if no bytes were available assume it'll contain valid data from one of the previous reads when data was available
}
void ClassName::sloConnectionError()
{
qDebug() << "ERROR!!";
}
//QLocalSocket namedPipe, QByteArray byteArray and QTimer timer are available as member variables.
QString pipeName="Get it from Registry";
connect(&namedPipe,SIGNAL(connected()),this,SLOT(sloConnected()));
connect(&namedPipe,SIGNAL(error(QLocalSocket::LocalSocketError)),this,SLOT(sloConnectionError()));
namedPipe.connectToServer(pipeName,QIODevice::ReadOnly);
void ClassName::sloConnected()
{
connect(&timer,SIGNAL(timeout()),this,SLOT(sloProcess()));
timer.start(200); //i need to update my clients with the changed/unchanged data at regular intervals
}
void ClassName::sloProcess()
{
if(namedPipe.bytesAvailable())
byteArray=namedPipe.readAll();
//deal with byteArray. if no bytes were available assume it'll contain valid data from one of the previous reads when data was available
}
void ClassName::sloConnectionError()
{
qDebug() << "ERROR!!";
}
To copy to clipboard, switch view to plain text mode
The Application that creates and writes to the pipe keeps running. The problem is that when i close my program and re-run it, it prints "ERROR!!".
Bookmarks