Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QProcess not accepting arguments in MacOS (works in Windows)

    General and Desktop
    4
    9
    1092
    Loading More Posts
    • 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.
    • R
      Rory_1 last edited by

      I am running Qt 5.10 on MacOS 10.13.2

      I am trying to open photoshop with one or more selected images in MacOS. In terminal this works:

      open "/Users/roryhill/Pictures/4K/2017-01-25_0030-Edit.jpg" -a "Adobe Photoshop CS6"
      

      The following works in Windows but not MacOS:

      QString app = "\"/Applications/Adobe Photoshop CS6/Adobe Photoshop CS6.app\"";  // diff file path for windows
      QStringList arguments;
      arguments << "/Users/roryhill/Pictures/4K/2017-01-25_0030-Edit.jpg";
      QProcess *process = new QProcess();
      process->start(app, arguments);
      

      In MacOS I get the error: "FailedToStart". If I drop the arguments in the last line and use:

      process->start(app);
      

      then photoshop opens, so the path to the photoshop executable is working.

      I have also tried using the executable inside the app container:

      "/Applications/Adobe Photoshop CS6/Adobe Photoshop CS6.app/Contents/MacOS/Adobe Photoshop CS6"
      

      Again this works to open photoshop but fails when arguments are added.

      This also fails:

      process->setArguments(arguments);
      process->setProgram(app);
      process->start();
      

      Omitting setArguments() fails too using this procedure:

      process->setProgram(app);
      process->start();
      

      Could this be some permissions issue in MacOS?

      1 Reply Last reply Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        Hi
        What happens if you do ?
        QDesktopServices::openUrl(QUrl("file:///Users/roryhill/Pictures/4K/2017-01-25_0030-Edit.jpg"));

        R 1 Reply Last reply Reply Quote 0
        • R
          Rory_1 @mrjj last edited by

          @mrjj said in QProcess not accepting arguments in MacOS (works in Windows):

          QDesktopServices::openUrl(QUrl("file:///Users/roryhill/Pictures/4K/2017-01-25_0030-Edit.jpg"));

          That opens the image in preview, so I guess permissions are okay.

          R 1 Reply Last reply Reply Quote 0
          • R
            Rory_1 @Rory_1 last edited by

            @Rory_1

            If I change the executable to preview:

            app = "/Applications/Preview.app";
            

            then it all works as expected, so the issue seems to be with photoshop. I have also tried the latest version of photoshop with the same issues.

            1 Reply Last reply Reply Quote 0
            • M
              mpergand last edited by

              try to use open.

              open -b org.mozilla.firefox "Samsung A3 2017.pdf"
              

              open the pdf file with Firefox
              (I don't have photoshop)
              Tape "man open" in the Terminal for details.

              R 1 Reply Last reply Reply Quote 0
              • R
                Rory_1 @mpergand last edited by

                @mpergand said in QProcess not accepting arguments in MacOS (works in Windows):

                try to use open.

                open -b org.mozilla.firefox "Samsung A3 2017.pdf"
                

                open the pdf file with Firefox
                (I don't have photoshop)
                Tape "man open" in the Terminal for details.

                Thanks. I will try this. I have to take a family break and I will report back tomorrow.

                1 Reply Last reply Reply Quote 0
                • SGaist
                  SGaist Lifetime Qt Champion last edited by

                  Hi,

                  You'll likely have to use the full path to the executable within the application bundle rather than the bundle itself.

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

                  R 1 Reply Last reply Reply Quote 0
                  • R
                    Rory_1 @SGaist last edited by

                    @SGaist said in QProcess not accepting arguments in MacOS (works in Windows):

                    Hi,

                    You'll likely have to use the full path to the executable within the application bundle rather than the bundle itself.

                    Thanks for the suggestion. As I mentioned in my original post I have tried this and it did not work.

                    I think my issue is related to how MacOS manages file locks. I can get the code to work with preview once and then the next time I get an error "the file couldn’t be opened because you don’t have permission to view it." This seems to be a common problem where preview maintains a lock on the file after the application has been closed. I'm going to take a look at QLockFile to see if it can help.

                    R 1 Reply Last reply Reply Quote 0
                    • R
                      Rory_1 @Rory_1 last edited by

                      @Rory_1 Update: I have partially solved my problem by resetting permissions on my macbook.

                      diskutil resetUserPermissions / `id -u`
                      

                      The code now works consistently for all applications, including adobe Bridge, except photoshop. I assumed (bad plan) that photoshop accepted command line arguments (and it does in windows) but might not in MacOS.

                      I do not believe the remaining issues are related to QProcess so I am marking this as solved.

                      Thanks to @SGaist, @mpergand and @mrjj for your assistance!

                      1 Reply Last reply Reply Quote 1
                      • First post
                        Last post