Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • Hi,

    First question to start the conversation is, is it possible to do an IPC between 2 programs with 2 different compiler like embarcadero and qt?

    If yes:

    What i want to do is, there is an application of borland then when i press a button it will open the qt application, and then with the 2 programs running share some strings from qt to c++ builder.

    I saw something about QProcess on qt but i don't know how to use it, and if it could be used in this case.


  • Lifetime Qt Champion

    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.



  • 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++?



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



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


  • Qt Champions 2019

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



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


  • Lifetime Qt Champion

    Hi,

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



  • 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?


  • Qt Champions 2019

    @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



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


  • Lifetime Qt Champion

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


Log in to reply