Reputation: 21
I installed Qt creator 5.15 in my ubuntu18.
I checked documentation how to plot graphics in C++ on Qtcreator and would like to get data from external test c++ program called "test" with Qprocess.
Here is a simple main.cpp:
#include <iostream>
#include <iostream>
#include "ZFraction.h"
using namespace std;
int main()
{
ZFraction a(4,5);
ZFraction b(2);
ZFraction c,d;
c = a+b;
d = a*b;
cout << a << " + " << b << " = " << c << endl;
cout << a << " * " << b << " = " << d << endl;
return 0;
}
Here is my Qt creator program:
#include "mafenetre.h"
#include "ui_mafenetre.h"
//using namespace QtCharts;
const quint64 start=QDateTime::currentSecsSinceEpoch();
const int limiteRandom=2;
Mafenetre::Mafenetre(QWidget *parent) :
QDialog(parent),
ui(new Ui::Mafenetre)
{
ui->setupUi(this);
myprocess = new QProcess(this);
QString program = ("./test");
arguments << " ";
myprocess->start(program, arguments);
//myprocess->waitForReadyRead();
connect(monTimer,SIGNAL(timeout()),this,SLOT(refresh_graph()));
connect(myprocess,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
connect(myprocess,SIGNAL(readyReadStandardError()),this,SLOT(readyReadStandardError()));
}
void Mafenetre::readyReadStandardOutput(){
qDebug()<< myprocess->readAllStandardOutput();
}
void Mafenetre::readyReadStandardError(){
qDebug() << myprocess->readAllStandardError();
}
Mafenetre::~Mafenetre()
{
delete ui;
}
My question is from the c++ program, how can you get result of "d" or "c" variables as input of Qtcreator program ?
Upvotes: 0
Views: 146
Reputation: 2283
You must start the program after connecting.
#include "mafenetre.h"
#include "ui_mafenetre.h"
//using namespace QtCharts;
const quint64 start=QDateTime::currentSecsSinceEpoch();
const int limiteRandom=2;
Mafenetre::Mafenetre(QWidget *parent) :
QDialog(parent),
ui(new Ui::Mafenetre)
{
ui->setupUi(this);
myprocess = new QProcess(this);
QString program = ("./test");
arguments << " ";
connect(myprocess,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
connect(myprocess,SIGNAL(readyReadStandardError()),this,SLOT(readyReadStandardError()));
myprocess->start(program, arguments);
//myprocess->waitForReadyRead();
connect(monTimer,SIGNAL(timeout()),this,SLOT(refresh_graph()));
}
void Mafenetre::readyReadStandardOutput(){
qDebug()<< myprocess->readAllStandardOutput();
}
void Mafenetre::readyReadStandardError(){
qDebug() << myprocess->readAllStandardError();
}
Mafenetre::~Mafenetre()
{
delete ui;
}
Upvotes: 2