QT C 上的 QProcess 备份数据库++

发布于 2025-01-14 09:17:22 字数 490 浏览 3 评论 0原文

我想在QT程序中使用qprocess备份我的数据库,代码如下,但是备份时出现0kb,当我查看错误Qprocess: Destroyed while process("mysqldump.exe") is still running时。

QProcess dump(this);
QStringlist args;
QString path="C:/Users/mahmut/Desktop/dbbackupfile/deneme.sql";
args<<"-uroot"<<"-proot"<<"kopuz"<<">";
dump.setStandardOutputFile(path);
dump.start("mysqldump.exe",args);

if(!dump.waitForStarted(1000))
{
qDebug()<<dump.errorString();
}

你能帮助我吗?我不明白这个错误并确定备份文件。

I want to backup my database with qprocess in QT program, the code is as follows, but 0kb occurs when backing up and when I look at the error Qprocess: Destroyed while process("mysqldump.exe") is still runnuing.

QProcess dump(this);
QStringlist args;
QString path="C:/Users/mahmut/Desktop/dbbackupfile/deneme.sql";
args<<"-uroot"<<"-proot"<<"kopuz"<<">";
dump.setStandardOutputFile(path);
dump.start("mysqldump.exe",args);

if(!dump.waitForStarted(1000))
{
qDebug()<<dump.errorString();
}

Can you help to me? ı do not understand this error and okb back up file.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

oО清风挽发oО 2025-01-21 09:17:23

您的程序在进程完成之前终止,您需要使用static bool QProcess::startDetached(program,arguments,workingDirectory)或添加dump.waitForFinished();到末尾。

另外,您不需要添加“>”到争论。您已使用 dump.setStandardOutputFile(path), ">" 重定向输出不适用于进程,因为它需要 shell 来执行命令,QProcess 不使用 shell,它只运行一个进程而不是 shell 表达式。

Your program terminates before process finished, you need to either use static bool QProcess::startDetached(program, arguments, workingDirectory) or add dump.waitForFinished(); to the end.

Also, you dont need to add ">" to arguments. You already redirected output with dump.setStandardOutputFile(path), ">" does not work with process as it requires shell to execute command, QProcess does not use shell it just runs one process not shell expression.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文