c++ - 如何读取运行 QProcess 的输出并将特定数据保存到变量?
问题描述
我将从命令行视频播放器获取状态。当它运行时,它会输出以下行等。
[update_state]pid:0 status=PLAYING(last:PLAYING) err=0x0 curtime=4 (ms:4983) fulltime=-1 lsttime=4
所以我想读取该输出并将其实时保存到变量中。
#include "system.h"
QProcess * player = new QProcess();
QString current_status;
QString last_status;
int current_time;
int full_time;
int lsttime;
system::system(QObject *parent) : QObject(parent)
{
}
void system::start(QString url)
{
player->start("player", QStringList(url));
}
下面更新
#include "system.h"
QProcess *player = new QProcess();
system::system(QObject *parent) : QObject(parent)
{
}
void system::start(QString url)
{
stop();
player->start("player", QStringList(url));
connect(player,SIGNAL(readyReadStandardOutput()),this,SLOT(readyReadStandardOutput()));
connect(player,SIGNAL(readyReadStandardError()),this,SLOT(readyReadStandardError()));
}
void system::readyReadStandardOutput(){
qDebug() << player->readAllStandardOutput();
}
void system::readyReadStandardError(){
//player->readAllStandardError();
}
解决方案
推荐阅读
- java - 科尔多瓦/移动优先应用程序中的“主要版本 51 比 5 新”
- php - 安装的 Composer 模块是否独立于操作系统?
- postgresql - 使用 PSQL 中的函数仅更新最后更新的行
- python - 如何在 gpu 上训练 haar 级联
- elasticsearch - Elasticsearch 错误 - 集群健康状态从 [YELLOW] 更改为 [RED](原因:[shards failed
- java - 一个JSON对象怎么用Java?
- ios - 如何在单元测试目标中的测试用例之间删除应用程序?
- powershell - 获取分钟并使用 SendKeys 输出它们
- ios - 将默认数据库路径更改为组路径后,iOS RealmSwift 不会更新模型
- amazon-web-services - 具有多个登录选项的 aws cognito 池