[SOLVED] Start QProcess out of QML Issue



  • Hi Guys,

    I would like to start an application out of Qt Quick and check if it was started successfully or if it was closed by the user. So I wrote a small plugin to access Qt's QProcess functionality out of Qt Quick. It works for starting some applications, but when I check whether the application is running, it always says true (also when not running). What's wrong here?

    @
    C++ code:
    void Launcher::launch(const QString &program, const QStringList &arguments)
    {
    m_process->startDetached(testString, arguments);
    }

    bool Launcher::isRunning()
    {
    return m_process->Running? true : false;
    }

    QML code:
    Launcher {
    id: exampleLauncher
    }

    ...
    exampleLauncher.launch(programName, arguments)
    exampleLauncher.isRunning()
    @

    Thank you for your help.


  • Moderators

    Hi,

    You should use state() to check the current state and not the enum value.
    @
    return m_process->state()==QProcess::Running ? true : false;
    @

    Edit: Removed Extra =



  • My program crashes if I read out the m_process->state(). I don't understand this... Do you have any idea for that problem?


  • Moderators

    Probably because the object is not initialized. Put a condition to check if it is null before the return statement.



  • Works perfectly, thank you!:)

    Another error was to use startDetached() instead of start().


  • Moderators

    Glad that it worked :)
    Please mark the post as solved by editing the post title and prepend [solved]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.