QProcess Communication
-
I have two apps both created in QT. I want to start the one app by the other. its fine. What I need to know is ,how to send some signals (contains arguments) to the second app using the first app.
Please reply me with sample code for sending the message (first app) and receiving (second app) it. -
Hi,
You need to use an IPC system like e.g. QLocalSocket/Server. Have a look at Qt's documentation for IPC examples
-
This is coded in Qt console application
@int main(int argc, char *argv[])
{
QLocalSocket * m_socket = new QLocalSocket();
m_socket->connectToServer("SomeServer"); //how to give server name or is it path...if(m_socket->waitForConnected(1000))
{
//send a message to the server
QByteArray block;
QDataStream out(&block, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_7);
out << "x";
out.device()->seek(0);
m_socket->write(block);
m_socket->flush();
QMessageBox box;
box.setText("mesage has been sent");
box.exec();
...
}@
And this in Qt widget application
where to create the below function...
@
void MainWindow::messageReceived()
{QLocalServer *m_pServer;
QLocalSocket *clientConnection = m_pServer->nextPendingConnection();while (clientConnection->bytesAvailable() < (int)sizeof(quint32))
clientConnection->waitForReadyRead();connect(clientConnection, SIGNAL(disconnected()),
clientConnection, SLOT(deleteLater()));QDataStream in(clientConnection);
in.setVersion(QDataStream::Qt_4_7);
if (clientConnection->bytesAvailable() < (int)sizeof(quint16)) {
return;
}QString message;
in >> message;QMessageBox box;
box.setText(QString(message));
box.exec();
}@I got both applications output but i didn't saw any communication between them.
Please help... -
You application will crash because of line 5, you use m_pServer->nextPendingConnection and on't instantiate it first.