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. Inter-Process Communication between an c++ builder program and a QT creator program

Inter-Process Communication between an c++ builder program and a QT creator program

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 5 Posters 995 Views
  • 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi,

    Here you have various IPC technologies that you can use to interact with different types of application. They are not exclusive to Qt even if there are classes that are provided to make your life easier to use them.

    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
    3
    • F Offline
      F Offline
      frnklu20
      wrote on last edited by
      #3

      I know how to use the QProcess class with 2 programs of qt and not with 2 programs of different compilers, that's the problem for me.
      Do you have any example of a IPC between a qt creator and another compiler of c++?

      JonBJ 1 Reply Last reply
      0
      • F frnklu20

        I know how to use the QProcess class with 2 programs of qt and not with 2 programs of different compilers, that's the problem for me.
        Do you have any example of a IPC between a qt creator and another compiler of c++?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #4

        @frnklu20
        Compilers are not relevant. Qt Creator is not relevant. Even Qt is not relevant. You need to explain how that

        and then with the 2 programs running share some strings from qt to c++ builder.

        works.

        QProcess works regardless of whether the sub-process being run is written with Qt or not.

        1 Reply Last reply
        2
        • F Offline
          F Offline
          frnklu20
          wrote on last edited by frnklu20
          #5

          Hi,

          I did a research and came to the the conclusion to use Tcp Sockets to exchange data between these 2 processes .

          So i made a tcp server app and a tcp client app using Qt Creator and it works just fine, the connection to the server and the data exchange between them works! After that, i made a tcp server app and a tcp client app using RAD Studio and it also works just fine, the connection to the server and the data exchange between them works!

          But there is a problem, when i try to exchange data between the tcp client app made with Qt and the tcp server app using RAD studio (both applications connected to the same Local Host IP 127.0.0.1 and the same Port: 4040) it doesn't work! They are able to get connected but the message that i send from the client doesn't appears in the server application.
          I don't know why this is not working.

          Tcp Client in Qt

          Widget::Widget(QWidget *parent)
              : QWidget(parent)
              , ui(new Ui::Widget),
                m_socket(new QTcpSocket(this)),
                m_socketReady(false)
          {
              ui->setupUi(this);
              setWindowTitle("Client | Data Sender");
              m_socket ->connectToHost("localhost",4040);
          
              connect(m_socket, &QTcpSocket::connected,this,&Widget::socketReady);
              connect(m_socket, &QTcpSocket::stateChanged,this,&Widget::stateChanged);
          }
          
          Widget::~Widget()
          {
              m_socket->close();
              delete ui;
          }
          
          void Widget::socketReady()
          {
              m_socketReady = true;
          }
          
          void Widget::stateChanged(QAbstractSocket::SocketState socketState)
          {
              qDebug()<<socketState;
          }
          
          void Widget::on_send_clicked()
          {
              if(m_socketReady)
              {
                  QDataStream out(m_socket);
                  out<<ui->lineEdit->text(); //when i press the send button
                  update();                 //it sends the message written in the QLineEdit
              }
          }
          

          Tcp Server in RAD studio

          void __fastcall TfrmMain::btnStartClick(TObject *Sender)
          {
          	ServerSocket1->Port = edtPort->Value;
          	ServerSocket1->Active = True;
          	meoLog->Lines->Add("Server Started");
                 //press the start button ant it connects to the Port number that is in a TLineEdit
                 //the value  written is 4040
          }
          //---------------------------------------------------------------------------
          void __fastcall TfrmMain::btnStopClick(TObject *Sender)
          {
          	ServerSocket1->Active = False;
                 meoLog->Lines->Add("Server Stopped");//meoLog is like QTextEdit
          }
          //---------------------------------------------------------------------------
          void __fastcall TfrmMain::ServerSocket1ClientConnect(TObject *Sender, TCustomWinSocket *Socket)
          
          {
          	meoLog->Lines->Add(Socket->RemoteAddress + ':' + Socket->RemotePort);
          }
          //---------------------------------------------------------------------------
          void __fastcall TfrmMain::ServerSocket1ClientDisconnect(TObject *Sender, TCustomWinSocket *Socket)
          
          {
              meoLog->Lines->Add(Socket->RemoteAddress + ':' + Socket->RemotePort);
          }
          //---------------------------------------------------------------------------
          void __fastcall TfrmMain::ServerSocket1ClientRead(TObject *Sender, TCustomWinSocket *Socket)
          
          {
          	meoLog->Lines->Add(ServerSocket1->Socket->Connections[0]->ReceiveText());
          }
          //---------------------------------------------------------------------------
          void __fastcall TfrmMain::btnSendClick(TObject *Sender)
          {
          	if(ServerSocket1->Socket->ActiveConnections >0)
          	{
          	   ServerSocket1->Socket->Connections[0]->SendText(edtMsg->Text);
              }
          

          Why they do not exchange data if they get connected?.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @frnklu20 said in Inter-Process Communication between an c++ builder program and a QT creator program:

            Why they do not exchange data if they get connected?.

            They exchange data but since c++ builder doesn't know anything about QDataStream the data can not be handled. You have to use your own protocol.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            3
            • F Offline
              F Offline
              frnklu20
              wrote on last edited by
              #7

              And how can i do this? Do you have any examples?

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

                Hi,

                Do not use QDataStream. Only QByteArray containing the data you want to send.

                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
                2
                • F Offline
                  F Offline
                  frnklu20
                  wrote on last edited by
                  #9

                  IT WORKED!

                  It works sending a QString too!(I don't know why)

                  But what is not working is:

                  Client.cpp

                  void Widget::on_send_clicked()
                  {
                      if(m_socketReady)
                      {
                          QString text = ui->lineEdit->text();
                          QByteArray msg(text);
                          m_socket->write(msg);
                  
                          update();
                      }
                  }
                  

                  Trying to send messages between 2 chats, but this gives me an error in QByteArray
                  error: no matching constructor for initialization of 'QByteArray'
                  What i'm doing wrong?

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @frnklu20 said in Inter-Process Communication between an c++ builder program and a QT creator program:

                    What i'm doing wrong?

                    You forgot to convert the QString to a QByteArray (exactly what the error message tells you).
                    See QString::toUtf8() for example

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    3
                    • F Offline
                      F Offline
                      frnklu20
                      wrote on last edited by
                      #11

                      DONE
                      thanks guys for all the support.
                      you are amazing!

                      mrjjM 1 Reply Last reply
                      1
                      • F frnklu20

                        DONE
                        thanks guys for all the support.
                        you are amazing!

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @frnklu20
                        Hi please flag as solved using the "topic tools" button in your first post then :)

                        1 Reply Last reply
                        1

                        • Login

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