I 在 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();
}
http://doc.qt.io/qt-5/qprocess.html#communicating-via-channels
您是否记得链接到并检查标准错误通道?
http://doc.qt.io/qt-5/qprocess.html#readAllStandardError
这在过去为我开始的一些 QProcesses 修复了它。
我这样做的另一种方法是使用QProcess::startDetached();
希望有帮助。
我的研究表明,rsync 的行为可能类似于 scp,因此这个答案在重定向时不会生成输出。