Qt和Linux管道
我已经编写了一个程序,从用户指定的HTML网站中删除标记。我知道创建一个GUI程序来配合这一点,允许用户输入URL 我有下面的代码,它打开一个管道来打开我制作的可执行文件,该文件处理来自QT程序的输入Qt和Linux管道,qt,pipe,Qt,Pipe,我已经编写了一个程序,从用户指定的HTML网站中删除标记。我知道创建一个GUI程序来配合这一点,允许用户输入URL 我有下面的代码,它打开一个管道来打开我制作的可执行文件,该文件处理来自QT程序的输入 QString stringURL = ui->lineEdit->text(); const char* result; ui->labelError->clear(); if(stringURL.isEmpty() || stringU
QString stringURL = ui->lineEdit->text();
const char* result;
ui->labelError->clear();
if(stringURL.isEmpty() || stringURL.isNull()) {
ui->labelError->setText("You have not entered a URL.");
stringURL.clear();
return;
}
std::string cppString = stringURL.toStdString();
const char* cString = cppString.c_str();
FILE *fid;
fid = popen("htmlstrip", "w"); //Note that this application is in the PATH
fprintf(fid, "%s\n", cString); //Send URL
pclose(fid);
然而,上面的代码只允许我写入管道。有谁能告诉我,我将如何允许Qt程序将输入发送到可执行文件,然后在完成处理后从可执行文件接收输出,并将其放入Qt程序的文本框/文本区域?您可以使用
#包括
#包括
#包括
int main()
{
过程回波;
//调用您的程序(例如echo)并将输入作为参数添加
开始(“echo”,QStringList()嗯…打开它“rw”并从管道中读取?
#include <QDebug>
#include <QProcess>
#include <QString>
int main()
{
QProcess echo;
// call your program (e.g. echo) and add your input as argument
echo.start("echo", QStringList() << "foo bar");
// wait until your program has finished
if (!echo.waitForFinished())
return 1;
// read the output
qDebug() << echo.readAll();
return 0;
}