Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess Communication

QProcess Communication

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    aniljoby
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You need to use an IPC system like e.g. QLocalSocket/Server. Have a look at Qt's documentation for IPC examples

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        aniljoby
        wrote on last edited by
        #3

        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...

        http://stackoverflow.com/questions/13061079/qlocalsocket-to-qlocalserver-message-being-corrupted-during-transfer

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You application will crash because of line 5, you use m_pServer->nextPendingConnection and on't instantiate it first.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved