Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QProcess revisted...
Forum Update on Monday, May 27th 2025

QProcess revisted...

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 2 Posters 351 Views
  • 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    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

    JonBJ 1 Reply Last reply
    0
    • SPlattenS 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)
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @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
      2
      • SPlattenS Offline
        SPlattenS Offline
        SPlatten
        wrote on last edited by
        #3

        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

        JonBJ 1 Reply Last reply
        0
        • SPlattenS SPlatten

          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.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @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.

          SPlattenS 1 Reply Last reply
          0
          • JonBJ 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.

            SPlattenS Offline
            SPlattenS Offline
            SPlatten
            wrote on last edited by
            #5

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

            Kind Regards,
            Sy

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved