Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QProcess with External script that kills the main process.

QProcess with External script that kills the main process.

Scheduled Pinned Locked Moved Mobile and Embedded
3 Posts 3 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.
  • F Offline
    F Offline
    f3tz3r
    wrote on last edited by
    #1

    So for my job i'm implementing an automatic update ability to the application.

    Our application versions are controlled via the RPM system. When i run the RPM update command ("rpm -U {rpm file}"), the RPM file kills the current running application process, corrects the applications files / directories / configuration, and moves the new executable and an autostart script restarts the application.

    My current implementation is the following:

    MainWindow.cpp:

    • Receives message that an update is needed
    • Waits for the application to be idle before updating
    • Once idle, sanity checks where the new code is, and that it is applicable
    • Emits a signal caught by a controller to execute the file when idle

    Controller.cpp:

    • Receives the signal for update
    • Start script to do the update.

    Controller.cpp:
    @
    //Function to call the update script
    void Controller::updateCode(){
    DEBUG("CTRL UPDATE CODE");

    /*
    system("/home/app/updateScript.sh");
    */

    QProcess *process = new QProcess(this);
    
    QString file = "/home/app/updateScript.sh";
    

    // bool x = process->startDetached(file, QStringList());
    // bool x = process->startDetached(file);
    int x = process->execute(file);

    DEBUG("START (%d)", x);
    
    QObject::connect(process, SIGNAL(error(QProcess::ProcessError)), this, SLOT(processError(QProcess::ProcessError)));
    
    DEBUG("PROCESS STATE (%d)", process->state());
    

    }
    @

    updateScript.sh:

    @
    if [ ! -d "/home/app/installedCode" ];
    then
    echo "Creating /home/app/installedCode directory"
    mkdir /home/app/installedCode
    fi

    FILE="$(ls -G /home/app/newCode/)"
    echo $FILE

    if [ -f "/home/app/newCode/$FILE" ];
    then

        MYPATH="$(readlink -f newCode/$FILE)"
    
        echo $MYPATH
    
        eval "rpm -U " $MYPATH
    
        mv "/home/app/newCode/$FILE" "/home/app/installedCode/"
    

    else
    echo "No file to update"
    fi
    @

    Here is the log for the currently attempted process:
    @
    01-19 12:31:07.079 - [controller.cpp:2240] - Simulating SC Update Message
    01-19 12:31:07.079 - [mainwindow.cpp:521] - Got request to update code. Waiting for idle
    01-19 12:31:10.978 - [mainwindow.cpp:514] - System optimal for update
    01-19 12:31:10.979 - [mainwindow.cpp:477] - System idle. Updating code
    01-19 12:31:10.979 - [controller.cpp:1211] - CTRL UPDATE CODE
    01-19 12:31:11.163 - [controller.cpp:1223] - START (0)
    01-19 12:31:11.163 - [controller.cpp:1227] - PROCESS STATE (0)
    @

    The .rpm file is moved from the newCode/ directory to the installedCode/ directory, so i know the script is getting called. But the running application is not getting killed like it should be.

    If i call the updateScript.sh file from the command line on the unit instead of the application, it does exactly what i expect.

    I also tried the process->startDetached() function as you can see where it is commented out. It does the same thing that execute() does.

    Any help is appreciated, thanks!

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      If I understood you correctly, you can emit a custom signal from Controller.cpp once the process completes, catch it in MainWindow.cpp and call close() of MainWindow.cpp.

      157

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

        Depending on the application connecting to QApplication::quit will ensure that the application is closing. The quitOnLastWindowClosed flag might be unset so closing windows might not be enough

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        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