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. macOs Qprocess, calling a unix exec
Forum Updated to NodeBB v4.3 + New Features

macOs Qprocess, calling a unix exec

Scheduled Pinned Locked Moved Unsolved General and Desktop
17 Posts 5 Posters 1.4k Views 2 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.
  • M MatthewFelton
    16 May 2023, 06:47

    Hello, im a super noob learning Qt and i thought id jump into making a nice little gui for an application that runs in the terminal/command prompt called avrdude. everythings going great so far i first made a console application that calls avrdude via QProcess. it works great on both mac and windows. now i have added a gui and the code itself is almost identical but for some reason it doesnt work.

        QString exePath {};
        QString comPort{};
        QString config {};
    
        if (os == "macOs")
        {
            comPort = "/dev/"+ connectedPort;
            exePath = "avrdude/mac/avrdude";
            config = "-Cavrdude/mac/avrdude.conf";
        }
        if (os == "windows")
        {
            comPort = connectedPort;
            exePath = "avrdude/win/avrdude";
            config = "-Cavrdude/win/avrdude.conf";
        }
    
        QStringList args =(QStringList()
                            << config
                            << "-v"
                            << "-patmega32u4"
                            << "-cavr109"
                            << "-P"
                            << comPort
                            << "-b57600"
                            << "-D"
                            << updateString
                            );
    
    
    
        QProcess pro;
        pro.waitForStarted();
        pro.start(exePath,args);
        pro.waitForFinished();
    

    This code runs as a console app perfectly on mac and windows. It also runs perfectly on windows as a Gui application but on mac it doesn't work as a Gui application. it simply runs the command, doesn't do anything then finishes. i tried catching errors with QProcess. unknown error. programme doesnt crash , it completes, it just doesnt open the terminal and run the args. Maybe i have to open the terminal directly first and then run the args. i notice on window running the avrdude.exe opens the command prompt whereas on mac it doesnt know what to do with the unix exec file avrdude.

    P Offline
    P Offline
    Pl45m4
    wrote on 16 May 2023, 10:06 last edited by
    #4

    @MatthewFelton said in macOs Qprocess, calling a unix exec:

    on mac it doesn't work as a Gui application

    If you are making a GUI app, you should use the asynchronous API and not the blocking, synchronous one.

    • https://doc.qt.io/qt-6/qprocess.html#synchronous-process-api

    Take advantage of QProcess signals

    • https://doc.qt.io/qt-6/qprocess.html#signals

    This also allows better error management with stateChanged and errorOccurred signals


    If debugging is the process of removing software bugs, then programming must be the process of putting them in.

    ~E. W. Dijkstra

    M 1 Reply Last reply 16 May 2023, 10:47
    1
    • P Pl45m4
      16 May 2023, 10:06

      @MatthewFelton said in macOs Qprocess, calling a unix exec:

      on mac it doesn't work as a Gui application

      If you are making a GUI app, you should use the asynchronous API and not the blocking, synchronous one.

      • https://doc.qt.io/qt-6/qprocess.html#synchronous-process-api

      Take advantage of QProcess signals

      • https://doc.qt.io/qt-6/qprocess.html#signals

      This also allows better error management with stateChanged and errorOccurred signals

      M Offline
      M Offline
      MatthewFelton
      wrote on 16 May 2023, 10:47 last edited by MatthewFelton
      #5

      @Pl45m4 are you saying this might help with using qprocess::error() in determining what is wrong ? having a quick read of this and being a complete beginner is this saying something about it blocking if called from the main thread because if so I do infact have this class running in a worker thread.

      J 1 Reply Last reply 16 May 2023, 11:14
      0
      • M MatthewFelton
        16 May 2023, 10:47

        @Pl45m4 are you saying this might help with using qprocess::error() in determining what is wrong ? having a quick read of this and being a complete beginner is this saying something about it blocking if called from the main thread because if so I do infact have this class running in a worker thread.

        J Online
        J Online
        JonB
        wrote on 16 May 2023, 11:14 last edited by JonB
        #6

        @MatthewFelton said in macOs Qprocess, calling a unix exec:

        I do infact have this class running in a worker thread

        This may or may not have anything to do with your Mac problem, but why do you have any threads, especially if you are beginner? Large numbers of beginners put threads in when there is no need, and threads are a major source of complexity/bugs. If you try your code from the main/single UI thread does it make any difference to the bad behaviour?

        M 1 Reply Last reply 16 May 2023, 18:10
        3
        • M MatthewFelton
          16 May 2023, 06:47

          Hello, im a super noob learning Qt and i thought id jump into making a nice little gui for an application that runs in the terminal/command prompt called avrdude. everythings going great so far i first made a console application that calls avrdude via QProcess. it works great on both mac and windows. now i have added a gui and the code itself is almost identical but for some reason it doesnt work.

              QString exePath {};
              QString comPort{};
              QString config {};
          
              if (os == "macOs")
              {
                  comPort = "/dev/"+ connectedPort;
                  exePath = "avrdude/mac/avrdude";
                  config = "-Cavrdude/mac/avrdude.conf";
              }
              if (os == "windows")
              {
                  comPort = connectedPort;
                  exePath = "avrdude/win/avrdude";
                  config = "-Cavrdude/win/avrdude.conf";
              }
          
              QStringList args =(QStringList()
                                  << config
                                  << "-v"
                                  << "-patmega32u4"
                                  << "-cavr109"
                                  << "-P"
                                  << comPort
                                  << "-b57600"
                                  << "-D"
                                  << updateString
                                  );
          
          
          
              QProcess pro;
              pro.waitForStarted();
              pro.start(exePath,args);
              pro.waitForFinished();
          

          This code runs as a console app perfectly on mac and windows. It also runs perfectly on windows as a Gui application but on mac it doesn't work as a Gui application. it simply runs the command, doesn't do anything then finishes. i tried catching errors with QProcess. unknown error. programme doesnt crash , it completes, it just doesnt open the terminal and run the args. Maybe i have to open the terminal directly first and then run the args. i notice on window running the avrdude.exe opens the command prompt whereas on mac it doesnt know what to do with the unix exec file avrdude.

          P Offline
          P Offline
          Pl45m4
          wrote on 16 May 2023, 11:38 last edited by Pl45m4
          #7

          @MatthewFelton said in macOs Qprocess, calling a unix exec:

          i notice on window running the avrdude.exe opens the command prompt whereas on mac it doesnt know what to do with the unix exec file avrdude

          One more thing besides the Qt / thread stuff:
          Does the stuff you are passing to QProcess work at all when putting it in a Mac Terminal?
          You've mentioned that Mac doesn't seem to find (or being able to run) the avrdude executable?!


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          J P 2 Replies Last reply 16 May 2023, 11:40
          0
          • P Pl45m4
            16 May 2023, 11:38

            @MatthewFelton said in macOs Qprocess, calling a unix exec:

            i notice on window running the avrdude.exe opens the command prompt whereas on mac it doesnt know what to do with the unix exec file avrdude

            One more thing besides the Qt / thread stuff:
            Does the stuff you are passing to QProcess work at all when putting it in a Mac Terminal?
            You've mentioned that Mac doesn't seem to find (or being able to run) the avrdude executable?!

            J Online
            J Online
            JonB
            wrote on 16 May 2023, 11:40 last edited by
            #8

            @Pl45m4

            @MatthewFelton said in macOs Qprocess, calling a unix exec:

            i first made a console application that calls avrdude via QProcess. it works great on both mac and windows. now i have added a gui and the code itself is almost identical but for some reason it doesnt work.

            ?

            1 Reply Last reply
            0
            • P Pl45m4
              16 May 2023, 11:38

              @MatthewFelton said in macOs Qprocess, calling a unix exec:

              i notice on window running the avrdude.exe opens the command prompt whereas on mac it doesnt know what to do with the unix exec file avrdude

              One more thing besides the Qt / thread stuff:
              Does the stuff you are passing to QProcess work at all when putting it in a Mac Terminal?
              You've mentioned that Mac doesn't seem to find (or being able to run) the avrdude executable?!

              P Offline
              P Offline
              Pl45m4
              wrote on 16 May 2023, 11:49 last edited by
              #9

              @MatthewFelton said in macOs Qprocess, calling a unix exec:

              i notice on window running the avrdude.exe opens the command prompt whereas on mac it doesnt know what to do with the unix exec file avrdude

              @JonB

              !

              :)

              No idea whether the command works at all now or not. @MatthewFelton should verify that first before digging deeper into QProcess and why it does or doesn't work.


              If debugging is the process of removing software bugs, then programming must be the process of putting them in.

              ~E. W. Dijkstra

              1 Reply Last reply
              1
              • J JonB
                16 May 2023, 11:14

                @MatthewFelton said in macOs Qprocess, calling a unix exec:

                I do infact have this class running in a worker thread

                This may or may not have anything to do with your Mac problem, but why do you have any threads, especially if you are beginner? Large numbers of beginners put threads in when there is no need, and threads are a major source of complexity/bugs. If you try your code from the main/single UI thread does it make any difference to the bad behaviour?

                M Offline
                M Offline
                MatthewFelton
                wrote on 16 May 2023, 18:10 last edited by MatthewFelton
                #10

                @JonB The code is a little more complicated than the snippet I showed you. I'm using a worker thread because I have a while loop looking for the Arduino and it was stopping my Gui from drawing when the arduino was unplugged. its all good. I have an interface class talking between the threaded class and my QML Gui and everything working great. apart from the QProcess issue on mac. so just to re-iterate.

                I created a console application first. Its works for both mac and windows. I then created a GuiApplication and utilized the console app code. On windows the GuiApplication works as expected but on mac the GuiApplication does not. Its like it doesnt call the exepath... or does call the expath but doesnt input the arguments. I have tested the same code in the terminal and it also works. And as previously stated the exact same code is also currently working on mac for the console application.

                S 1 Reply Last reply 16 May 2023, 18:46
                0
                • M MatthewFelton
                  16 May 2023, 18:10

                  @JonB The code is a little more complicated than the snippet I showed you. I'm using a worker thread because I have a while loop looking for the Arduino and it was stopping my Gui from drawing when the arduino was unplugged. its all good. I have an interface class talking between the threaded class and my QML Gui and everything working great. apart from the QProcess issue on mac. so just to re-iterate.

                  I created a console application first. Its works for both mac and windows. I then created a GuiApplication and utilized the console app code. On windows the GuiApplication works as expected but on mac the GuiApplication does not. Its like it doesnt call the exepath... or does call the expath but doesnt input the arguments. I have tested the same code in the terminal and it also works. And as previously stated the exact same code is also currently working on mac for the console application.

                  S Offline
                  S Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on 16 May 2023, 18:46 last edited by
                  #11

                  Hi,

                  How do you move the helper executable to the right on macOS ?

                  On macOS you do not have a single executable file for a GUI application like you have for a CLI application. A bundle is created by default.

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

                  M 1 Reply Last reply 16 May 2023, 20:07
                  0
                  • S SGaist
                    16 May 2023, 18:46

                    Hi,

                    How do you move the helper executable to the right on macOS ?

                    On macOS you do not have a single executable file for a GUI application like you have for a CLI application. A bundle is created by default.

                    M Offline
                    M Offline
                    MatthewFelton
                    wrote on 16 May 2023, 20:07 last edited by
                    #12

                    @SGaist it's a Unix executable. Not a bundle. It's designed to be used in the terminal

                    S 1 Reply Last reply 16 May 2023, 20:08
                    0
                    • M MatthewFelton
                      16 May 2023, 20:07

                      @SGaist it's a Unix executable. Not a bundle. It's designed to be used in the terminal

                      S Offline
                      S Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on 16 May 2023, 20:08 last edited by
                      #13

                      I am talking about your application not the helper.

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

                      M 1 Reply Last reply 16 May 2023, 20:28
                      0
                      • S SGaist
                        16 May 2023, 20:08

                        I am talking about your application not the helper.

                        M Offline
                        M Offline
                        MatthewFelton
                        wrote on 16 May 2023, 20:28 last edited by
                        #14

                        @SGaist as a complete beginner I don't actually know what that means sorry.

                        S 1 Reply Last reply 17 May 2023, 19:27
                        0
                        • M MatthewFelton
                          16 May 2023, 20:28

                          @SGaist as a complete beginner I don't actually know what that means sorry.

                          S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 17 May 2023, 19:27 last edited by
                          #15

                          Check the macOS deployment chapter in Qt's documentation. It's nicely explained.

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

                          M 1 Reply Last reply 18 May 2023, 05:59
                          0
                          • S SGaist
                            17 May 2023, 19:27

                            Check the macOS deployment chapter in Qt's documentation. It's nicely explained.

                            M Offline
                            M Offline
                            MatthewFelton
                            wrote on 18 May 2023, 05:59 last edited by
                            #16

                            @SGaist ok .. but I'm not deploying yet. I'm still building.

                            S 1 Reply Last reply 18 May 2023, 07:41
                            0
                            • M MatthewFelton
                              18 May 2023, 05:59

                              @SGaist ok .. but I'm not deploying yet. I'm still building.

                              S Offline
                              S Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 18 May 2023, 07:41 last edited by
                              #17

                              That is clear. However, the build still generates a bundle as described there. Hence my question about where your helper application is stored with regard to where the application executable can actually be found which should be in the generated bundle.

                              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

                              13/17

                              16 May 2023, 20:08

                              • Login

                              • Login or register to search.
                              13 out of 17
                              • First post
                                13/17
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • Users
                              • Groups
                              • Search
                              • Get Qt Extensions
                              • Unsolved