Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. [SOLVED] Start QProcess out of QML Issue
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Start QProcess out of QML Issue

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 2 Posters 2.5k 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.
  • E Offline
    E Offline
    Eddi0406
    wrote on last edited by
    #1

    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.

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

      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 =

      157

      1 Reply Last reply
      0
      • E Offline
        E Offline
        Eddi0406
        wrote on last edited by
        #3

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

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

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

          157

          1 Reply Last reply
          0
          • E Offline
            E Offline
            Eddi0406
            wrote on last edited by
            #5

            Works perfectly, thank you!:)

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

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

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

              157

              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