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. Stragne behavior with QProcess
Forum Updated to NodeBB v4.3 + New Features

Stragne behavior with QProcess

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 3 Posters 363 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.
  • ademmlerA Offline
    ademmlerA Offline
    ademmler
    wrote on last edited by ademmler
    #1

    hi folks.

    I am coding and working on MacOS X. This is important to know.
    In my main.app I want to launch two different external applications.
    Both are also written in QT. Let us call them first.app and second.app

    The code I am using for that task is:

    QString cmd = "/usr/bin/open";
    QStringList arguments;
        arguments << "-a"
                  << "path-toapplication";
    
        mcProcess = new QProcess(this);
        mcProcess->start(cmd, arguments);
        qDebug() << mcProcess->program() << " " << mcProcess->arguments();
    
    1. The first app launches (process is running).
      But it takes very long and the window only appears, when I move (shake) the main window from the main app.

    2. The second.app and the main.app crashes direct after the process has started.

    Note: I have tested the launch command "/usr/bin/open -a /path-to-application" from Mac OS X terminal.
    In both cases the command is successful and both apps appear very fast and do not crash.

    Any ideas?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      @ademmler said in Stagne behavior with QProcess:

      The first app launches (process is running).
      But it takes very long and the window only appears, when I move (shake) the main window from the main app.

      This sounds like your code is not returning to the event loop. We cannot see any of that in the snippet you posted.

      The second app crashes direct after the process has started.

      QProcess::error() returns what?
      QProcess:: exitCode() returns what?
      QProcess::state() ?
      Anything useful in the result of QProcess::readAllStandardOutput() or QProcess::readAllStandardError()?

      Do you even need the /usr/bin/open command? You are not passing a file name to open with the specified application which seems to be the purpose of "open".

      ademmlerA 2 Replies Last reply
      1
      • C ChrisW67

        @ademmler said in Stagne behavior with QProcess:

        The first app launches (process is running).
        But it takes very long and the window only appears, when I move (shake) the main window from the main app.

        This sounds like your code is not returning to the event loop. We cannot see any of that in the snippet you posted.

        The second app crashes direct after the process has started.

        QProcess::error() returns what?
        QProcess:: exitCode() returns what?
        QProcess::state() ?
        Anything useful in the result of QProcess::readAllStandardOutput() or QProcess::readAllStandardError()?

        Do you even need the /usr/bin/open command? You are not passing a file name to open with the specified application which seems to be the purpose of "open".

        ademmlerA Offline
        ademmlerA Offline
        ademmler
        wrote on last edited by ademmler
        #3

        @ChrisW67 Hi Chris thx for your response.

        I have to correct my words:
        The second.app and the main.app crashes direct after the process has started.

        I will added your response codes and "magic" now the app does not crash any longer.
        But I have to say - by some other reasons" I upgraded to Qt from 5.12 to 5.15.
        Hence I can't say if this solved the issue ....

        There is no file to be open. But it is the official way to launch an app on Mac OSX.
        If you just call the app path you get:

        /Applications/second.app
        -bash: /Applications/second.app: is a directory
        

        And if you call /Applications/second.app/Contents/MacOS/executable you have a terminal window popping up.

        Thx for helping me ...

        1 Reply Last reply
        0
        • C ChrisW67

          @ademmler said in Stagne behavior with QProcess:

          The first app launches (process is running).
          But it takes very long and the window only appears, when I move (shake) the main window from the main app.

          This sounds like your code is not returning to the event loop. We cannot see any of that in the snippet you posted.

          The second app crashes direct after the process has started.

          QProcess::error() returns what?
          QProcess:: exitCode() returns what?
          QProcess::state() ?
          Anything useful in the result of QProcess::readAllStandardOutput() or QProcess::readAllStandardError()?

          Do you even need the /usr/bin/open command? You are not passing a file name to open with the specified application which seems to be the purpose of "open".

          ademmlerA Offline
          ademmlerA Offline
          ademmler
          wrote on last edited by
          #4

          @ChrisW67 Me again.

          In case of the first app I get an unknown error:

          QString cmd = "/usr/bin/open";
          
              QStringList arguments;
              arguments << "-a"
                        << "/Applications/ColorNavigator 7.app";
          
              mcProcess = new QProcess(this);
              mcProcess->start(cmd, arguments);
          
              qDebug() << mcProcess->program() << " " << mcProcess->arguments();    
              qDebug() << mcProcess->error();
              qDebug() << mcProcess->exitCode();
              qDebug() << mcProcess->state();
          }
          

          The response:

          QProcess::Starting
          "/usr/bin/open"   ("-a", "/Applications/ColorNavigator 7.app")
          QProcess::UnknownError
          0
          QProcess::Starting
          

          An unknown error can be everything. Is there some option to bring this process to the foreground?

          jsulmJ 1 Reply Last reply
          0
          • ademmlerA ademmler

            @ChrisW67 Me again.

            In case of the first app I get an unknown error:

            QString cmd = "/usr/bin/open";
            
                QStringList arguments;
                arguments << "-a"
                          << "/Applications/ColorNavigator 7.app";
            
                mcProcess = new QProcess(this);
                mcProcess->start(cmd, arguments);
            
                qDebug() << mcProcess->program() << " " << mcProcess->arguments();    
                qDebug() << mcProcess->error();
                qDebug() << mcProcess->exitCode();
                qDebug() << mcProcess->state();
            }
            

            The response:

            QProcess::Starting
            "/usr/bin/open"   ("-a", "/Applications/ColorNavigator 7.app")
            QProcess::UnknownError
            0
            QProcess::Starting
            

            An unknown error can be everything. Is there some option to bring this process to the foreground?

            jsulmJ Offline
            jsulmJ Offline
            jsulm
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @ademmler Can you try with a path without spaces?

            https://forum.qt.io/topic/113070/qt-code-of-conduct

            ademmlerA 1 Reply Last reply
            0
            • jsulmJ jsulm

              @ademmler Can you try with a path without spaces?

              ademmlerA Offline
              ademmlerA Offline
              ademmler
              wrote on last edited by
              #6

              @jsulm

              The first.app has no space. Also I tried the second without:

              "/usr/bin/open"   ("-a", "/Applications/ColorNavigator7.app")
              Process error: QProcess::UnknownError
              Process exit code: 0
              Process state: QProcess::Starting
              

              As you see the same state and error. But now Colornavigator crashed ;-)
              Hence the developer of Colornavigator have used a hardcoded path somehow ...

              1 Reply Last reply
              0
              • C Offline
                C Offline
                ChrisW67
                wrote on last edited by
                #7

                @ademmler, currently the process has not had time to start before your debug output. Just for diagnostic purposes try explicitly waiting for the process to start and finish:

                bool success = mcProcess->waitForStarted(5000);
                qDebug() << mcProcess->program() << " " << mcProcess->arguments() << "started" << success ;    
                success = mcProcess->waitForFinished(5000);
                qDebug() << mcProcess->program() << " " << mcProcess->arguments() << "finished" << success;    
                qDebug() << mcProcess->error();
                qDebug() << mcProcess->exitCode();
                qDebug() << mcProcess->state();
                

                or you could connect the QProcess objects to slots to handle errorOccurred(), finished(), etc.

                ademmlerA 1 Reply Last reply
                4
                • C ChrisW67

                  @ademmler, currently the process has not had time to start before your debug output. Just for diagnostic purposes try explicitly waiting for the process to start and finish:

                  bool success = mcProcess->waitForStarted(5000);
                  qDebug() << mcProcess->program() << " " << mcProcess->arguments() << "started" << success ;    
                  success = mcProcess->waitForFinished(5000);
                  qDebug() << mcProcess->program() << " " << mcProcess->arguments() << "finished" << success;    
                  qDebug() << mcProcess->error();
                  qDebug() << mcProcess->exitCode();
                  qDebug() << mcProcess->state();
                  

                  or you could connect the QProcess objects to slots to handle errorOccurred(), finished(), etc.

                  ademmlerA Offline
                  ademmlerA Offline
                  ademmler
                  wrote on last edited by
                  #8

                  @ChrisW67 thx for your help. I tested your hint,
                  After a long while the second.app appears. Regardless what QtProcess is responding.

                  "/usr/bin/open"   ("-a", "/Applications/ColorNavigator 7.app") started false
                  "/usr/bin/open"   ("-a", "/Applications/ColorNavigator 7.app") finished false
                  Process error: QProcess::Timedout
                  Process exit code: 0
                  Process state: QProcess::Running
                  

                  Looks like that this app is simple very slow at launch ...

                  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