【发布时间】:2023-03-17 23:21:02
【问题描述】:
我在 QProcess 中启动 rsync。如果我使用QProcess::startDetached(),我的进程运行良好(在它自己的终端中),但如果我使用QProcess:start() 启动它,则没有任何反应。问题似乎是 QProcess 显然无法从 rsync 读取消息并将其写入输出窗口。
我已经在构造函数中连接了这个信号。
MainWindow::~MainWindow()
{
process = new QProcess(this);
connect( process, SIGNAL(readyReadStandardOutput()), this, SLOT(onReadyReadStandardOutput() ) );
}
点击按钮后我调用:
void MainWindow::onButton1Clicked()
{
process->start("rsync -a root@10.0.0.1:/path/ /rsync_folder");
//process->start("ping 10.0.0.01"); // this works for testing and I see output but not the above.
}
当 rsync 启动时,它会打印一条消息并要求输入密码。我的 QProcess 没有收到任何消息,但收到了 ping 消息。这里可能有什么问题?
上面的悲伤行也可以直接在 Windows 7 命令行上运行,但它似乎没有显示 QProcess 的任何进展。
更新
这是我显示输出的方式。
void MainWindow::onReadyReadStandardOutput()
{
qDebug() << process->readAllStandardOutput();
}
【问题讨论】:
-
请澄清一下,您如何知道您的应用程序收到了来自
ping命令的消息?除非您通过readAllStandardOutput方法从QProcess显式读取它们并将其写入日志或其他地方,否则它们不应该是可见的。 -
@olegandriyanove 我已将插槽连接到它,我正在使用
qDebug()打印到输出窗口