Search code examples
qt4mysqldatabase-restoreqprocess

Restoring MySQL database with QProcess , can't really work with simple redirect like '<'


So first retrieve file name by QFileDialog , into fName , and:

  QProcess *proc = new QProcess ();
  QStringList arguments;
  arguments << "-u" << "USER_NAME"
            << "-pPASS_WORD" << "<"
              << fName;
#ifdef WIN32
    proc->start("mysql.exe" , arguments);
#else
    proc->start("mysql" , arguments);
#endif

But this just dont't work , i always see the output of what "mysql --help" does , seems that wrong parameters are provided. However , manually execute this works.


Solution

  • You shouldn't redirect stdin with arguments. Use setStandartInputFile(const QString & fileName) instead.