"Finished" signal of a Qprocess is not called

Asked

Viewed 47 times

1

In my project I have a Main responsible for executing a QThread and on this wheel a QProcess responsible for creating a postgresql backup file.

Well the main works properly by calling the QThread which also works by creating and running QProcess, thus creating the archive.

But I need to know when the process ends, so I created a connect with a Signal already existing in the QProces" by name finished, this one that has as SLOT created by me, but this Signal is never called I wonder if there is something wrong in mine(which I have already reviewed several times), or if it is not possible to use this Signal in a QThread.

Any hint is welcome. Thank you.

Follows the code:

Threadpgdump. h:

 #ifndef THREADPGDUMP_H
 #define THREADPGDUMP_H
 #include "QObject"
 #include "QThread"
 #include "QString"
 #include "QProcess


class ThreadPgDump : public QThread{

      Q_OBJECT

   public:
      explicit ThreadPgDump(QObject *parent = 0);
      ~ThreadPgDump();


      //---------------------------------
      // SET

       void setPgDumpPath(QString pgDumpPath) { this->hostName = pgDumpPath; }

       void setParameters(
           QString hostName,
           QString databaseName,
           int port,
           QString username,
           QString password,
           QString backupPathFileName)
       {
           this->hostName = hostName;
           this->databaseName = databaseName;
           this->port = port;
           this->username = username;
           this->password = password;
           this->backupPathFileName = backupPathFileName;
       }

       void kill();


   private:

       QString  pgDumpPath;
       QString  hostName;
       QString  databaseName;
       int      port;
       QString  username;
       QString  password;
       QString  backupPathFileName;
       QProcess *process;

       //---------------------------------
       // FUNC

       bool procDefineEnvironment();
       QString getPgDump();


   protected:

       void run();


   signals:

       void finishedPgDump();



   public slots:

       void slotProgressFinished(int);


};

 #endif // THREADPGDUMP_H

Threadpgdump.cpp:

 #include "ThreadPgDump.h"
 #include "qdebug.h"
 #include "QProcess"

//-----------------------------------------------------------------------------

ThreadPgDump::ThreadPgDump(QObject *parent) : QThread(parent){

}

//-----------------------------------------------------------------------------

ThreadPgDump::~ThreadPgDump(){

}

//-----------------------------------------------------------------------------

void ThreadPgDump::run(){


    process = new QProcess(this->parent());

    connect(process, SIGNAL(finished(int)), this, SLOT(slotProgressFinished(int)));

    procDefineEnvironment();

    QString command;

    command.clear();

    command.append(getPgDump());

    command.append("--host ").append(hostName).append(" ");

    command.append("--port ").append(QString().sprintf("%d", port)).append(" ");

    command.append("--username \"").append(username).append("\" ");

    command.append("--format custom ");

    command.append("--blobs ");

    command.append("--verbose ");

    command.append("--file \"").append(backupPathFileName).append("\" ");

    command.append("\"").append(databaseName).append("\"");

    process->start(command);

}

//-----------------------------------------------------------------------------


QString ThreadPgDump::getPgDump(){

     if( pgDumpPath.length() > 0 ){
         return pgDumpPath;
     }
     else{
         #ifdef __linux__
             return QString("/usr/bin/pg_dump ");
         #endif

         #ifdef WIN32
             return QString("c:/pg_dump.exe ");
         #endif
     }
}

//-----------------------------------------------------------------------------

 void ThreadPgDump::kill(){

     if( process != NULL ){

         process->kill();

     }
}

//-----------------------------------------------------------------------------

bool ThreadPgDump::procDefineEnvironment(){

     QStringList env = QProcess::systemEnvironment();
     env.append(QString("PGPASSWORD=").append(password));
     process->setEnvironment(env);
     process->setProcessChannelMode(QProcess::MergedChannels);

     return true;
}

//-----------------------------------------------------------------------------


void ThreadPgDump::slotProgressFinished(int exitNumber){

    qDebug() << "TESTE";

}

//-----------------------------------------------------------------------------

1 answer

1


Browser other questions tagged

You are not signed in. Login or sign up in order to post.