Question

Hi im trying to run a simple QProcess, here is my very basic code.

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

What is wrong with this? I have chaged the code to this

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);

Im now getting the error

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

I have changed the line

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

It now compiles but im still not getting a dump file

Was it helpful?

Solution

Change the following line:

arguments << "sweetassurfwear > sweetassurfwear.sql";

to:

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

You need to handle the different strings as separate arguments.

OTHER TIPS

According to Qt Documentation you should do something similar to :

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

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

Notice the way you should give your mysqldump app its command line arguments.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top