Here is a dummy sample code for the master app:
It uses the Qt framework, and is a Qt console application.
Type ping in the console, and the C# app should answer ping back.
#include <QCoreApplication>
#include <QProcess>
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
// Path to the C# executable
QString program = "D:/Documents/ConsoleApplication1/ConsoleApplication1/bin/Release/ConsoleApplication1.exe";
// Start child Process
QProcess * process = new QProcess();
process->setProgram(program);
// Execute lambda function whenever a message from the process is received
QObject::connect(process, &QProcess::readyReadStandardOutput, [&](){ cout << process->readAll().toStdString(); } );
process->start();
string text;
cin >> text;
process->write( QByteArray::fromStdString(text) + "\r\n" );
return a.exec();
}
No comments:
Post a Comment