无法在Qt4的QProcess中正确启动mysqldump

Can't launch correctly mysqldump in QProcess of Qt4

我正在尝试从 Qt4 应用程序 (Debian 6) 中的远程主机下载 sql 转储。

QProcess process_one(this), process_two(this);
    QStringList args1, args2;
    args1 << "--host=192.168.0.1" << "--user=root" << "--password=root" << "nfc tag";
    args2 << "--user=root" << "--password=8KQ90fV9" << "nfc_sink";
    process_one.setStandardOutputFile("/home/Volchok/nfc.sql");
    //process_two.setStandardInputFile("/home/Volchok/nfc.sql");
    process_one.start("mysqldump", args1);
    while(!process_one.waitForFinished(-1));
    if (process_one.exitStatus()){
        std::cout << "Control Window: error with mysqldump process\n";
        return;
    }
    qDebug()<< "error in mysqldump process: " << process_one.error();
    /*process_two.start("mysql", args2);
    while(!process_two.waitForFinished());
    if (process_two.exitStatus()){
        std::cout << "Control Window: error with mysql process\n";
        return;
    }
    qDebug()<< "error in mysql process: " << process_two.error();*/

应用程序启动我的sql转储,创建 nfc.sql 文件,但它是空的!

-- MySQL dump 10.13  Distrib 5.1.49, for debian-linux-gnu (i486)
--
-- Host: 192.168.0.1    Database: nfc tag
-- ------------------------------------------------------
-- Server version   5.5.43-0+deb7u1

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

终端中的相同命令行工作正常。 nfc.sql 文件获取更多数据。 QProcess 以代码 5 结束。 远程主机 - Raspberry Pi B+。 为什么 qprocess 不能正常工作?我做错了什么?

问题出在

args1 << "--host=192.168.0.1" << "--user=root" << "--password=root" << "nfc tag";

应该是

args1 << "--host=192.168.0.1" << "--user=root" << "--password=root" << "nfc" << "tag";

分享我的解决方案案例:Qt5 + mariadb 10。 这不起作用:

QProcess::execute("mysqldump -uabcdef --password='123456' abcdef ");

这个有效:

QProcess::execute("mysqldump -uabcdef --password=\"123456\" abcdef ");

所有代码:

    QProcess process;
    String exe = "mysqldump -uabcdef --password=\"123456\" abcdef";
    process.start(exe);
    process.waitForFinished();
    QFile file(filename);
    if (!file.open(QIODevice::WriteOnly)) {
        qDebug()<<__FUNCTION__<<__LINE__<<" mysqldump is error! ";
        return;
    }
    file.write(process.readAllStandardOutput());
    file.close();