一个简单的QProcess

时间:2014-01-07 00:40:15

标签: c++ qt qt4 qprocess qtcore

我想尝试运行一个简单的QProcess,这是我的基本代码。

QDir("/home/brett/sweetback");
        QProcess process;
        process.start("mysqldump -uroot -ppass sweetassurfwear > sweetassurfwear.sql");
        process.waitForFinished(-1);

这有什么问题? 我已将代码改为此

QString program = "/usr/bin/mysqldump";
QStringList arguments;
arguments << "-uroot";
arguments << "-ppass";
arguments << "--routines";
arguments << "sweetassurfwear > sweetassurfwear.sql";
//All the other arguments

QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);

我现在收到错误

sweetgui2.cpp: In member function ‘void SweetGuiForm::on_buttonBox_accepted()’:
sweetgui2.cpp:88: error: no matching function for call to ‘QProcess::QProcess(<unresolved overloaded function type>)’
/usr/include/QtCore/qprocess.h:219: note: candidates are: QProcess::QProcess(const QProcess&)
/usr/include/QtCore/qprocess.h:129: note:                 QProcess::QProcess(QObject*)
make: *** [sweetgui2.o] Error 1

我更改了行

QProcess *myProcess = new QProcess(parent);
to
QProcess *myProcess = new QProcess(this);

它现在编译但我仍然没有获得转储文件

2 个答案:

答案 0 :(得分:1)

更改以下行:

arguments << "sweetassurfwear > sweetassurfwear.sql";

为:

arguments << "sweetassurfwear" << ">" << "sweetassurfwear.sql";

您需要将不同的字符串作为单独的参数处理。

答案 1 :(得分:0)

根据Qt文档,你应该做类似的事情:

QString program = "PathTo/mysqldump";
QStringList arguments;
arguments << "-uroot";
arguments << "-ppass";
//All the other arguments

QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);

请注意您应该为mysqldump应用程序提供命令行参数的方式。