Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved QProcess revisted...

    General and Desktop
    2
    5
    166
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • SPlatten
      SPlatten last edited by SPlatten

      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)
      

      Kind Regards,
      Sy

      JonB 1 Reply Last reply Reply Quote 0
      • JonB
        JonB @SPlatten last edited by

        @SPlatten
        IIRC: Working directory is set after locating the executable to run. If mysqldump.exe is not on your PATH, 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.

        1 Reply Last reply Reply Quote 2
        • JonB
          JonB @SPlatten last edited by

          @SPlatten
          IIRC: Working directory is set after locating the executable to run. If mysqldump.exe is not on your PATH, 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.

          1 Reply Last reply Reply Quote 2
          • SPlatten
            SPlatten last edited by

            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.

            Kind Regards,
            Sy

            JonB 1 Reply Last reply Reply Quote 0
            • JonB
              JonB @SPlatten last edited by JonB

              @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 1 Reply Last reply Reply Quote 0
              • SPlatten
                SPlatten @JonB last edited by

                @JonB , found the issue, stupid but you have to add --databases to the command line.

                Kind Regards,
                Sy

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post