QProcess revisted...
-
Having gotten it working using QProcess::execute, now I'm revisiting the original:
QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << QString("--skip-comments") << QString("--compact") << QString("--lock-tables=false") << QString("--add-drop-database") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()); QProcess* pobjProc(new QProcess(this)); if ( pobjProc != nullptr ) { QObject::connect(pobjProc, &QProcess::errorOccurred, [pobjProc](QProcess::ProcessError eError) { qdbg() << "ERROR: " << eError; } ); QObject::connect(pobjProc, &QProcess::stateChanged, [pobjProc](QProcess::ProcessState eState) { if ( eState == QProcess::Running ) { const qint64 cint64PID = pobjProc->processId(); if ( cint64PID > 0 ) { } } }); pobjProc->setStandardOutputFile(strFilename); pobjProc->setWorkingDirectory(strDBinstFolder); pobjProc->start(strApp, slstArguments); }
The parameters, output filename strFilename:
C:/Users/splatten/Documents/TrainerS1D5.sql
Working directory strDBinstFolder:
C:/Program Files (x86)/MariaDB 10.5/bin/
strApp:
mysqldump.exe
Arguments, slstArguments:
--skip-comments --compact --lock-tables=false --add-drop-database --host=localhost --user=trainer --password=PASSWORD training
There is an error as soon as the process starts and a 0 byte file created:
ERROR: QProcess::ProcessError(FailedToStart)
-
Having gotten it working using QProcess::execute, now I'm revisiting the original:
QString strApp(DataSets::mscszMariaDBdumpApp); QStringList slstArguments; slstArguments << QString("--skip-comments") << QString("--compact") << QString("--lock-tables=false") << QString("--add-drop-database") << (QString(DataSets::mscszOptionHost) + Trainer::strHost()) << (QString(DataSets::mscszOptionUser) + Trainer::strUser()) << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword()) << (Trainer::strDatabase()); QProcess* pobjProc(new QProcess(this)); if ( pobjProc != nullptr ) { QObject::connect(pobjProc, &QProcess::errorOccurred, [pobjProc](QProcess::ProcessError eError) { qdbg() << "ERROR: " << eError; } ); QObject::connect(pobjProc, &QProcess::stateChanged, [pobjProc](QProcess::ProcessState eState) { if ( eState == QProcess::Running ) { const qint64 cint64PID = pobjProc->processId(); if ( cint64PID > 0 ) { } } }); pobjProc->setStandardOutputFile(strFilename); pobjProc->setWorkingDirectory(strDBinstFolder); pobjProc->start(strApp, slstArguments); }
The parameters, output filename strFilename:
C:/Users/splatten/Documents/TrainerS1D5.sql
Working directory strDBinstFolder:
C:/Program Files (x86)/MariaDB 10.5/bin/
strApp:
mysqldump.exe
Arguments, slstArguments:
--skip-comments --compact --lock-tables=false --add-drop-database --host=localhost --user=trainer --password=PASSWORD training
There is an error as soon as the process starts and a 0 byte file created:
ERROR: QProcess::ProcessError(FailedToStart)
@SPlatten
IIRC: Working directory is set after locating the executable to run. Ifmysqldump.exe
is not on yourPATH
, specify the full path to it for the program to execute.Also IIRC under Windows you may need to look at both stdout & stderr for error messages it puts there.
-
Yay! It works now a new problem, despite having --add-drop-database in the arguments, there is no DROP DATABASE or CREATE DATABASE in the output.
@SPlatten
I believe I used that, and it did have one of those SQL comment-y things at the top saying like "IF EXISTS DROP". I assume if you try this outside of Qt you get the same issue, so it's not Qt? In which case you'll have to Google for that.EDIT
You don't seem to have database correctly mentioned on your command line? So it won't generate any line. Have a read of e.g. https://stackoverflow.com/questions/16452523/mysqldump-with-create-database-line, the accepted answer there, and comment:That's what was happening with me. I wasn't using --databases or --all-databases. I just put the database name, which wouldn't create the drop database if exists and create database line.
-
@SPlatten
I believe I used that, and it did have one of those SQL comment-y things at the top saying like "IF EXISTS DROP". I assume if you try this outside of Qt you get the same issue, so it's not Qt? In which case you'll have to Google for that.EDIT
You don't seem to have database correctly mentioned on your command line? So it won't generate any line. Have a read of e.g. https://stackoverflow.com/questions/16452523/mysqldump-with-create-database-line, the accepted answer there, and comment:That's what was happening with me. I wasn't using --databases or --all-databases. I just put the database name, which wouldn't create the drop database if exists and create database line.