从外部c++程序获取结果



我在我的ubuntu18上安装了Qt creator 5.15。

我检查了如何在Qtcreator上用c++绘制图形的文档,并希望从外部测试c++程序中获得数据,称为&;test&;;Qprocess。

下面是一个简单的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;
}

这是我的Qt creator程序:

#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;
}

我的问题来自c++程序,你怎么能得到"d"或";c"变量作为Qtcreator程序的输入?

您必须在连接后启动程序。

#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;
}

相关内容

  • 没有找到相关文章

最新更新