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.
-
@frnklu20
Compilers are not relevant. Qt Creator is not relevant. Even Qt is not relevant. You need to explain how thatand 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?.
-
@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.
-
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? -
@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