【问题标题】:How to get INT variable to QProcess write command?如何将 INT 变量获取到 QProcess 写入命令?
【发布时间】:2020-12-12 21:30:57
【问题描述】:

以下代码有效

QProcess *p = new QProcess();
p->write("10 cats\n");

现在我需要将int 变量发送到write 命令。

类似:

QProcess *p = new QProcess();
int i = 10;
p->write(i << " cats\n");

【问题讨论】:

    标签: c++ qt qstring qprocess


    【解决方案1】:

    看起来你想附加变量然后将它们作为参数传递。

    试试这样的

    int i{10};
    QString formattedString{QString("%1 cats\n").arg(i)};
    QProcess* p = new QProcess();
    p->write(formattedString.toStdString().c_str());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-01
      相关资源
      最近更新 更多