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 not working.
Forum Updated to NodeBB v4.3 + New Features

QProcess not working.

Scheduled Pinned Locked Moved Solved General and Desktop
29 Posts 5 Posters 3.7k Views 1 Watching
  • 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 SPlatten

    I am using Qt 5.9.2 with MSVC2015 64bit. I am trying to execute mysqldump using QProcess. I've tried several different things, below is the latest code, none of these work and in the Event View I see:

    Log Name:      Application
    Source:        MariaDB
    Date:          26/07/2021 08:18:28
    Event ID:      100
    Task Category: None
    Level:         Warning
    Keywords:      Classic
    User:          N/A
    Computer:      LHR1-EUD-L20381
    Description:
    Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets)
     
    Event Xml:
    <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <System>
        <Provider Name="MariaDB" />
        <EventID Qualifiers="49152">100</EventID>
        <Version>0</Version>
        <Level>3</Level>
        <Task>0</Task>
        <Opcode>0</Opcode>
        <Keywords>0x80000000000000</Keywords>
        <TimeCreated SystemTime="2021-07-26T07:18:28.6591139Z" />
        <EventRecordID>149973</EventRecordID>
        <Correlation />
        <Execution ProcessID="0" ThreadID="0" />
        <Channel>Application</Channel>
        <Computer>LHR1-EUD-L20381</Computer>
        <Security />
      </System>
      <EventData>
        <Data>Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets)
     
    </Data>
      </EventData>
    </Event>
    

    My code:

    process* pobjProcess(new process(this));
                if ( pobjProcess != nullptr )
                {
                    QString strApp(DataSets::mscszMariaDBdumpApp);
                    QStringList slstArguments;
                    slstArguments << ("\"" + strDBinstFolder + strApp + "\"")
                                  << (QString(DataSets::mscszOptionHost) + Trainer::strHost())
                                  << (QString(DataSets::mscszOptionUser) + Trainer::strUser())
                                  << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword())
                                  << (Trainer::strDatabase())
                                  << (QString(">") + strFilename);
                    strApp = "";
                    foreach( QString strArg, slstArguments )
                    {
                        if ( strApp.isEmpty() != true )
                        {
                            strApp += " ";
                        }
                        strApp += strArg;
                    }
    qdbg() << strApp;
                    pobjProcess->setWorkingDirectory(strDBinstFolder);
                    pobjProcess->setArguments(slstArguments);
                    pobjProcess->setProgram(strApp);
                    pobjProcess->start();
                    QObject::connect(pobjProcess, &QProcess::stateChanged,
                        [pobjProcess](QProcess::ProcessState newState)
                        {
                            const qint64 cint64PID(pobjProcess->processId());
                            if ( newState == QProcess::NotRunning )
                            {
     
                            }
                            else if ( newState == QProcess::Running && cint64PID > 0 )
                            {
     
                            }
    qdbg() << "PID: " << cint64PID << ", newState: " << newState;
                        }
                    );
                }
    

    In the console I am seeing:

    PID: 4968, newState:  QProcess::ProcessState(NotRunning)
    

    The actual command line is:

    "C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql
    

    If I copy the above and paste into a command prompt, it works. But not from the application.

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #4

    @SPlatten Why don't you connect a slot to https://doc.qt.io/qt-5/qprocess.html#errorOccurred and check what https://doc.qt.io/qt-5/qiodevice.html#errorString returns?

    I would split "<< (QString(">") + strFilename);" into two parameters.

    process* pobjProcess(new process(this));
    if ( pobjProcess != nullptr )
    

    Why do you check pobjProcess pointer after alloocating memory? This is useless as in case of out of memory your app will be terminated anyway.

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    J.HilkJ 1 Reply Last reply
    1
    • jsulmJ jsulm

      @SPlatten Why don't you connect a slot to https://doc.qt.io/qt-5/qprocess.html#errorOccurred and check what https://doc.qt.io/qt-5/qiodevice.html#errorString returns?

      I would split "<< (QString(">") + strFilename);" into two parameters.

      process* pobjProcess(new process(this));
      if ( pobjProcess != nullptr )
      

      Why do you check pobjProcess pointer after alloocating memory? This is useless as in case of out of memory your app will be terminated anyway.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #5

      @jsulm said in QProcess not working.:

      This is useless as in case of out of memory your app will be terminated anyway.

      not necessarily
      I see 2 cases where one would do such a thing

      • if the OP compiles with -fno-exceptions than it will be indeed a null pointer returned instead of an exception
      • If the OP overloaded new and explicitly returns nullptr if some condition is met/not met

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • SPlattenS SPlatten

        I am using Qt 5.9.2 with MSVC2015 64bit. I am trying to execute mysqldump using QProcess. I've tried several different things, below is the latest code, none of these work and in the Event View I see:

        Log Name:      Application
        Source:        MariaDB
        Date:          26/07/2021 08:18:28
        Event ID:      100
        Task Category: None
        Level:         Warning
        Keywords:      Classic
        User:          N/A
        Computer:      LHR1-EUD-L20381
        Description:
        Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets)
         
        Event Xml:
        <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
          <System>
            <Provider Name="MariaDB" />
            <EventID Qualifiers="49152">100</EventID>
            <Version>0</Version>
            <Level>3</Level>
            <Task>0</Task>
            <Opcode>0</Opcode>
            <Keywords>0x80000000000000</Keywords>
            <TimeCreated SystemTime="2021-07-26T07:18:28.6591139Z" />
            <EventRecordID>149973</EventRecordID>
            <Correlation />
            <Execution ProcessID="0" ThreadID="0" />
            <Channel>Application</Channel>
            <Computer>LHR1-EUD-L20381</Computer>
            <Security />
          </System>
          <EventData>
            <Data>Aborted connection 84 to db: 'training' user: 'trainer' host: 'localhost' (Got an error reading communication packets)
         
        </Data>
          </EventData>
        </Event>
        

        My code:

        process* pobjProcess(new process(this));
                    if ( pobjProcess != nullptr )
                    {
                        QString strApp(DataSets::mscszMariaDBdumpApp);
                        QStringList slstArguments;
                        slstArguments << ("\"" + strDBinstFolder + strApp + "\"")
                                      << (QString(DataSets::mscszOptionHost) + Trainer::strHost())
                                      << (QString(DataSets::mscszOptionUser) + Trainer::strUser())
                                      << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword())
                                      << (Trainer::strDatabase())
                                      << (QString(">") + strFilename);
                        strApp = "";
                        foreach( QString strArg, slstArguments )
                        {
                            if ( strApp.isEmpty() != true )
                            {
                                strApp += " ";
                            }
                            strApp += strArg;
                        }
        qdbg() << strApp;
                        pobjProcess->setWorkingDirectory(strDBinstFolder);
                        pobjProcess->setArguments(slstArguments);
                        pobjProcess->setProgram(strApp);
                        pobjProcess->start();
                        QObject::connect(pobjProcess, &QProcess::stateChanged,
                            [pobjProcess](QProcess::ProcessState newState)
                            {
                                const qint64 cint64PID(pobjProcess->processId());
                                if ( newState == QProcess::NotRunning )
                                {
         
                                }
                                else if ( newState == QProcess::Running && cint64PID > 0 )
                                {
         
                                }
        qdbg() << "PID: " << cint64PID << ", newState: " << newState;
                            }
                        );
                    }
        

        In the console I am seeing:

        PID: 4968, newState:  QProcess::ProcessState(NotRunning)
        

        The actual command line is:

        "C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql
        

        If I copy the above and paste into a command prompt, it works. But not from the application.

        JonBJ Online
        JonBJ Online
        JonB
        wrote on last edited by
        #6

        @SPlatten said in QProcess not working.:

        "C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql

        You have chosen to use a DOS/Windows > redirection symbol on your command line. This cannot be executed directly, i.e. executing mysqldump and passing >... to it.

        If you do it this way you must execute via

        QStringList args { "/c", "\"C:\\Program Files (x86)\\MariaDB 10.5\\bin\\mysqldump\" --host=localhost --user=trainer --password=CobhamAC training >C:\\Users\\simon.platten\\Documents\\TrainerS1D5.sql"  };
        process->exec("cmd", args);
        

        Or handle the output redirection yourself in the caller, or via an "output-to" argument to mysqldump if it supports that.

        SPlattenS 1 Reply Last reply
        1
        • J.HilkJ J.Hilk

          @SPlatten said in QProcess not working.:

          pobjProcess->setArguments(slstArguments);
          pobjProcess->setProgram(strApp);

          hi,

          you do realise, that at this point strApp also has the arguments appended to it?

          it should be only the program, and the arguments as string list separately

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

          @J-Hilk , yes, it didn't originally, I add those later just to see if it made any difference.

          Kind Regards,
          Sy

          KroMignonK 1 Reply Last reply
          0
          • JonBJ JonB

            @SPlatten said in QProcess not working.:

            "C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training >C:/Users/simon.platten/Documents/TrainerS1D5.sql

            You have chosen to use a DOS/Windows > redirection symbol on your command line. This cannot be executed directly, i.e. executing mysqldump and passing >... to it.

            If you do it this way you must execute via

            QStringList args { "/c", "\"C:\\Program Files (x86)\\MariaDB 10.5\\bin\\mysqldump\" --host=localhost --user=trainer --password=CobhamAC training >C:\\Users\\simon.platten\\Documents\\TrainerS1D5.sql"  };
            process->exec("cmd", args);
            

            Or handle the output redirection yourself in the caller, or via an "output-to" argument to mysqldump if it supports that.

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

            @JonB , where are you getting process and exec from?

            Kind Regards,
            Sy

            JonBJ 1 Reply Last reply
            0
            • SPlattenS Offline
              SPlattenS Offline
              SPlatten
              wrote on last edited by SPlatten
              #9

              I've changed the code back to:

              process* pobjProcess(new process(this));
                          if ( pobjProcess != nullptr )
                          {
                              QString strApp(DataSets::mscszMariaDBdumpApp);
                              QStringList slstArguments;
                              slstArguments << ("\"" + strDBinstFolder + strApp + "\"")
                                            << (QString(DataSets::mscszOptionHost) + Trainer::strHost())
                                            << (QString(DataSets::mscszOptionUser) + Trainer::strUser())
                                            << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword())
                                            << (Trainer::strDatabase())
                                            << QString(">")
                                            << strFilename;
              qdbg() << slstArguments;
              qdbg() << strApp;
                              pobjProcess->setWorkingDirectory(strDBinstFolder);
                              pobjProcess->setArguments(slstArguments);
                              pobjProcess->setProgram(strApp);
                              pobjProcess->start();
                              QObject::connect(pobjProcess, &QProcess::errorOccurred,
                                   [this](QProcess::ProcessError err)
                                  {
              qdbg() << "Error: " << err;
                                  }
                              );
                              QObject::connect(pobjProcess, &QProcess::stateChanged,
                                  [pobjProcess](QProcess::ProcessState newState)
                                  {
                                      const qint64 cint64PID(pobjProcess->processId());
                                      if ( newState == QProcess::NotRunning )
                                      {
               
                                      }
                                      else if ( newState == QProcess::Running && cint64PID > 0 )
                                      {
               
                                      }
              qdbg() << "PID: " << cint64PID << ", newState: " << newState;
                                  }
                              );
                          }
              

              Still doesn't work and I'm not seeing anything errorOccurred

              Kind Regards,
              Sy

              1 Reply Last reply
              0
              • SPlattenS SPlatten

                @J-Hilk , yes, it didn't originally, I add those later just to see if it made any difference.

                KroMignonK Offline
                KroMignonK Offline
                KroMignon
                wrote on last edited by KroMignon
                #10

                @SPlatten said in QProcess not working.:

                yes, it didn't originally, I add those later just to see if it made any difference.

                I don't really know what is the purpose of this, I guess you have to get SQL statements from you DB.

                My way to achieve it would be:

                • start mysqldump with QProcess
                • wait until QProcess / mysqldump finished
                • read QProcess output (cf. QProcess::readAll()) ==> no need of redirection at all

                And last remark:
                you have to do connection before starting process, to be sure not to loose state changes ;)

                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                SPlattenS 1 Reply Last reply
                1
                • KroMignonK KroMignon

                  @SPlatten said in QProcess not working.:

                  yes, it didn't originally, I add those later just to see if it made any difference.

                  I don't really know what is the purpose of this, I guess you have to get SQL statements from you DB.

                  My way to achieve it would be:

                  • start mysqldump with QProcess
                  • wait until QProcess / mysqldump finished
                  • read QProcess output (cf. QProcess::readAll()) ==> no need of redirection at all

                  And last remark:
                  you have to do connection before starting process, to be sure not to loose state changes ;)

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

                  @KroMignon I don't follow you, if I copy the command line and arguments to a command prompt it works, the arguments are everything it needs for mysqldump to connect and export the database.

                  Kind Regards,
                  Sy

                  KroMignonK 1 Reply Last reply
                  0
                  • SPlattenS SPlatten

                    @JonB , where are you getting process and exec from?

                    JonBJ Online
                    JonBJ Online
                    JonB
                    wrote on last edited by
                    #12

                    @SPlatten said in QProcess not working.:

                    @JonB , where are you getting process and exec from?

                    It's an example of QProcess::exec(). Actually that's static. Exactly the same principle if you want to use pobjProcess->start();. It's the argument passing I'm trying to tell you about.

                    if I copy the command line and arguments to a command prompt it works,

                    Yes, as I said this will (only) work from cmd.

                                              << QString(">")
                    
                                              << strFilename;
                    

                    As I said, this won't work for mysqldump run as an executable. It will only work via cmd /c .... Up to you whether you believe me :)

                    SPlattenS 1 Reply Last reply
                    0
                    • SPlattenS SPlatten

                      @KroMignon I don't follow you, if I copy the command line and arguments to a command prompt it works, the arguments are everything it needs for mysqldump to connect and export the database.

                      KroMignonK Offline
                      KroMignonK Offline
                      KroMignon
                      wrote on last edited by KroMignon
                      #13

                      @SPlatten said in QProcess not working.:

                      I don't follow you, if I copy the command line and arguments to a command prompt it works, the arguments are everything it needs for mysqldump to connect and export the database.

                      With QProcess, you don't start the process from a shell / command prompt, that is the difference here.
                      Try this:

                      auto proc = new QProcess;
                      QObject::connect(proc, &QProcess::stateChanged,
                                          [proc](QProcess::ProcessState newState)
                      {
                          qDebug() << "new state is " <<  newState;
                          if(newState == QProcess::NotRunning)
                          {
                              QString output(proc->readAll());
                              qDebug() << "Output is" << output;
                              proc->delateLater();
                          }
                      });
                      proc->setWorkingDirectory(strDBinstFolder);
                      proc->start(strApp,slstArguments );
                      

                      EDIT: do NOT add redirection in slstArguments !!!

                      EDIT BIS:

                      QStringList slstArguments;
                      slstArguments << (QString(DataSets::mscszOptionHost) + Trainer::strHost())
                                                    << (QString(DataSets::mscszOptionUser) + Trainer::strUser())
                                                    << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword())
                                                    << (Trainer::strDatabase());
                      

                      ==> I suppose that DataSets::mscszOptionHost contains --host=

                      It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                      SPlattenS 2 Replies Last reply
                      1
                      • JonBJ JonB

                        @SPlatten said in QProcess not working.:

                        @JonB , where are you getting process and exec from?

                        It's an example of QProcess::exec(). Actually that's static. Exactly the same principle if you want to use pobjProcess->start();. It's the argument passing I'm trying to tell you about.

                        if I copy the command line and arguments to a command prompt it works,

                        Yes, as I said this will (only) work from cmd.

                                                  << QString(">")
                        
                                                  << strFilename;
                        

                        As I said, this won't work for mysqldump run as an executable. It will only work via cmd /c .... Up to you whether you believe me :)

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

                        @JonB , not in Qt 5.9.2 it ins't, execute ?

                        Kind Regards,
                        Sy

                        JonBJ 1 Reply Last reply
                        0
                        • SPlattenS SPlatten

                          @JonB , not in Qt 5.9.2 it ins't, execute ?

                          JonBJ Online
                          JonBJ Online
                          JonB
                          wrote on last edited by JonB
                          #15

                          @SPlatten
                          int QProcess::execute(const QString &program, const QStringList &arguments) [static]. So it's execute. It was introduced into some Qt. I don't know about 5.9.2.

                          As I said, forget I ever wrote exec or execute. The same argument processing applies to QProcess::start. You keep passing > argument, and I've explained this won't work.

                          SPlattenS 1 Reply Last reply
                          0
                          • KroMignonK KroMignon

                            @SPlatten said in QProcess not working.:

                            I don't follow you, if I copy the command line and arguments to a command prompt it works, the arguments are everything it needs for mysqldump to connect and export the database.

                            With QProcess, you don't start the process from a shell / command prompt, that is the difference here.
                            Try this:

                            auto proc = new QProcess;
                            QObject::connect(proc, &QProcess::stateChanged,
                                                [proc](QProcess::ProcessState newState)
                            {
                                qDebug() << "new state is " <<  newState;
                                if(newState == QProcess::NotRunning)
                                {
                                    QString output(proc->readAll());
                                    qDebug() << "Output is" << output;
                                    proc->delateLater();
                                }
                            });
                            proc->setWorkingDirectory(strDBinstFolder);
                            proc->start(strApp,slstArguments );
                            

                            EDIT: do NOT add redirection in slstArguments !!!

                            EDIT BIS:

                            QStringList slstArguments;
                            slstArguments << (QString(DataSets::mscszOptionHost) + Trainer::strHost())
                                                          << (QString(DataSets::mscszOptionUser) + Trainer::strUser())
                                                          << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword())
                                                          << (Trainer::strDatabase());
                            

                            ==> I suppose that DataSets::mscszOptionHost contains --host=

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

                            @KroMignon , I've tried this:

                            QString strApp(DataSets::mscszMariaDBdumpApp);
                            QStringList slstArguments;
                            slstArguments << ("\"" + strDBinstFolder + strApp + "\"")
                                          << (QString(DataSets::mscszOptionHost) + Trainer::strHost())
                                          << (QString(DataSets::mscszOptionUser) + Trainer::strUser())
                                          << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword())
                                          << (Trainer::strDatabase())
                                          << QString(">")
                                          << strFilename;
                            pobjProcess->setWorkingDirectory(strDBinstFolder);
                            pobjProcess->start(strApp, slstArguments);
                            QObject::connect(pobjProcess, &QProcess::errorOccurred,
                                [this](QProcess::ProcessError err) {
                            qDebug() << "Error: " << err;
                            });
                            QObject::connect(pobjProcess, &QProcess::stateChanged,
                                [pobjProcess](QProcess::ProcessState newState)  {
                                    const qint64 cint64PID(pobjProcess->processId());
                                    if ( newState == QProcess::NotRunning )  {
                                    }  else if ( newState == QProcess::Running && cint64PID > 0 )  {
                                    }
                            qDebug() << "PID: " << cint64PID << ", newState: " << newState;
                            });
                            

                            Kind Regards,
                            Sy

                            jsulmJ KroMignonK 2 Replies Last reply
                            0
                            • SPlattenS SPlatten

                              @KroMignon , I've tried this:

                              QString strApp(DataSets::mscszMariaDBdumpApp);
                              QStringList slstArguments;
                              slstArguments << ("\"" + strDBinstFolder + strApp + "\"")
                                            << (QString(DataSets::mscszOptionHost) + Trainer::strHost())
                                            << (QString(DataSets::mscszOptionUser) + Trainer::strUser())
                                            << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword())
                                            << (Trainer::strDatabase())
                                            << QString(">")
                                            << strFilename;
                              pobjProcess->setWorkingDirectory(strDBinstFolder);
                              pobjProcess->start(strApp, slstArguments);
                              QObject::connect(pobjProcess, &QProcess::errorOccurred,
                                  [this](QProcess::ProcessError err) {
                              qDebug() << "Error: " << err;
                              });
                              QObject::connect(pobjProcess, &QProcess::stateChanged,
                                  [pobjProcess](QProcess::ProcessState newState)  {
                                      const qint64 cint64PID(pobjProcess->processId());
                                      if ( newState == QProcess::NotRunning )  {
                                      }  else if ( newState == QProcess::Running && cint64PID > 0 )  {
                                      }
                              qDebug() << "PID: " << cint64PID << ", newState: " << newState;
                              });
                              
                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #17

                              @SPlatten Did you notice "EDIT: do NOT add redirection in slstArguments !!!" in @KroMignon post?
                              Why do you need redirection to a file if you can simply read the stdout from the process as @KroMignon already suggested?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              SPlattenS 1 Reply Last reply
                              0
                              • SPlattenS SPlatten

                                @KroMignon , I've tried this:

                                QString strApp(DataSets::mscszMariaDBdumpApp);
                                QStringList slstArguments;
                                slstArguments << ("\"" + strDBinstFolder + strApp + "\"")
                                              << (QString(DataSets::mscszOptionHost) + Trainer::strHost())
                                              << (QString(DataSets::mscszOptionUser) + Trainer::strUser())
                                              << (QString(DataSets::mscszOptionPassword) + Trainer::strPassword())
                                              << (Trainer::strDatabase())
                                              << QString(">")
                                              << strFilename;
                                pobjProcess->setWorkingDirectory(strDBinstFolder);
                                pobjProcess->start(strApp, slstArguments);
                                QObject::connect(pobjProcess, &QProcess::errorOccurred,
                                    [this](QProcess::ProcessError err) {
                                qDebug() << "Error: " << err;
                                });
                                QObject::connect(pobjProcess, &QProcess::stateChanged,
                                    [pobjProcess](QProcess::ProcessState newState)  {
                                        const qint64 cint64PID(pobjProcess->processId());
                                        if ( newState == QProcess::NotRunning )  {
                                        }  else if ( newState == QProcess::Running && cint64PID > 0 )  {
                                        }
                                qDebug() << "PID: " << cint64PID << ", newState: " << newState;
                                });
                                
                                KroMignonK Offline
                                KroMignonK Offline
                                KroMignon
                                wrote on last edited by KroMignon
                                #18

                                @SPlatten This don't make sense to me:

                                • Why do you add application into argument list?
                                • Why to you redirect it to a file and not directly read it for QProcess stream?

                                It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                                SPlattenS 1 Reply Last reply
                                1
                                • jsulmJ jsulm

                                  @SPlatten Did you notice "EDIT: do NOT add redirection in slstArguments !!!" in @KroMignon post?
                                  Why do you need redirection to a file if you can simply read the stdout from the process as @KroMignon already suggested?

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

                                  @jsulm The purpose of this is to provide an export / backup facility of the database to an SQL file.

                                  Kind Regards,
                                  Sy

                                  jsulmJ 1 Reply Last reply
                                  0
                                  • SPlattenS SPlatten

                                    @jsulm The purpose of this is to provide an export / backup facility of the database to an SQL file.

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #20

                                    @SPlatten You can still write the stdout from the process to a file...

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0
                                    • KroMignonK KroMignon

                                      @SPlatten This don't make sense to me:

                                      • Why do you add application into argument list?
                                      • Why to you redirect it to a file and not directly read it for QProcess stream?
                                      SPlattenS Offline
                                      SPlattenS Offline
                                      SPlatten
                                      wrote on last edited by
                                      #21

                                      @KroMignon , as I said earlier I've tried numerous things, thats just one of variant.

                                      Kind Regards,
                                      Sy

                                      jsulmJ 1 Reply Last reply
                                      0
                                      • SPlattenS SPlatten

                                        @KroMignon , as I said earlier I've tried numerous things, thats just one of variant.

                                        jsulmJ Offline
                                        jsulmJ Offline
                                        jsulm
                                        Lifetime Qt Champion
                                        wrote on last edited by jsulm
                                        #22

                                        @SPlatten Also, as @JonB already wrote: you can't use redirection without a shell. Redirection is a feature of a shell (cmd.exe on Windows). So, you will need to execute cmd.exe as executable and pass everything else as parameters.

                                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        1 Reply Last reply
                                        0
                                        • JonBJ JonB

                                          @SPlatten
                                          int QProcess::execute(const QString &program, const QStringList &arguments) [static]. So it's execute. It was introduced into some Qt. I don't know about 5.9.2.

                                          As I said, forget I ever wrote exec or execute. The same argument processing applies to QProcess::start. You keep passing > argument, and I've explained this won't work.

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

                                          @JonB , just tried:

                                          QProcess::execute(strApp);
                                          

                                          strApp contains:

                                          /c "C:/Program Files (x86)/MariaDB 10.5/bin/mysqldump" --host=localhost --user=trainer --password=CobhamAC training > C:/Users/simon.platten/Documents/TrainerS1D5.sql
                                          

                                          Still not working.

                                          Kind Regards,
                                          Sy

                                          jsulmJ JonBJ 2 Replies 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