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 exiting when invoked from a QThread
Forum Updated to NodeBB v4.3 + New Features

QProcess not exiting when invoked from a QThread

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.3k 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.
  • B Offline
    B Offline
    bemineni
    wrote on last edited by
    #1

    0 down vote favorite

    I am trying to install a RPM using QProcess(/bin/rpm). This QProcess is running in a concurrent thread which was started by another QThread.

       @QThread retThread = new CMyThread(this);
       connect(retThread, SIGNAL(finished()), retThread, SLOT(deleteLater()));
       retThread->start();@
    

    For some reason the QProcess keeps on running and never exits. When I get the pid of the QProcess and check using the ps command, I dont' see any rpm command that is being executed. The standard out and standard error both are merged on to a single channel and logged on to a file.

    The log indicates that the rpm command has finished the process of the installation.

    The same behavior is not seen when I run the rpm installation using the QProcess on the main thread. Is this anything related to the event loop. If so how to check if the event loop exists . As per to my knowledge a thread should automatically create the event loop from QT 4.4 and above. I am using QT 4.8

    http://qt-project.org/wiki/Threads_Events_QObjects

    I feel like the event loop exists, since I am getting other thread queued signals in this thread.

    @QString ORIGINAL_LOG_FILE = "/var/Component.log";

    int PROC_WAIT_TIME= 90000;
    QSharedPointer<QProcess>  process(new QProcess);
    
    
    QString program = "/bin/rpm";
    QStringList compArgs;
    
    compArgs << "-Uvh"<<"--nodeps"<<"some.rpm";
    
    
    QStringList configEnvironmentVars = process->systemEnvironment();
    
    
    process->setEnvironment(configEnvironmentVars);
    
    process->setWorkingDirectory("/tmp/something");
    
    connect(process.data() , SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(slot_finished(int,QProcess::ExitStatus)) );
    
    // process->setWorkingDirectory();
    process->setProcessChannelMode(QProcess::MergedChannels);
    process->setStandardOutputFile&#40;ORIGINAL_LOG_FILE, QIODevice::ReadWrite | QIODevice::Append | QIODevice::Text&#41;;
    process->start(program, compArgs);
    
    if (process->waitForStarted())
    {
      LOGINFO(m_nodeLogFile,QString("Waiting for the process to finish"));
      do
      {
         LOGINFO(m_nodeLogFile, QString("pid = %1").arg((uint)process->pid()));
         LOGINFO(m_nodeLogFile , QString("Error = %1").arg(process->error()));
         LOGINFO(m_nodeLogFile,QString("Envirnoment variables = %1").arg(configEnvironmentVars.join("\n")));
         LOGINFO(m_nodeLogFile,QString("Working directory = %1").arg(process->workingDirectory()));
         LOGINFO(m_nodeLogFile,QString("State = %1").arg(process->state()));
      }while(!process->waitForFinished(100));@
    
    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on last edited by
      #2

      First of all: looks like your Thread construction is wrong. Read this: "How To Really, Truly Use QThreads; The Full Explanation":http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation/

      And why are you waiting for process finishing in a loop? Using signal/slots are better approach....

      God is Real unless explicitly declared as Integer.

      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