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. why QProcess is not working in MAC os?
QtWS25 Last Chance

why QProcess is not working in MAC os?

Scheduled Pinned Locked Moved Solved General and Desktop
macrosqt 5.11.0bundleqprocess
19 Posts 6 Posters 5.3k Views
  • 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.
  • Y Offline
    Y Offline
    Yash001
    wrote on 17 Apr 2019, 17:33 last edited by
    #1

    Hi,

    I am using Qt 5.11.0. and MAC system. I am trying to call another software with help of QProcess.

    Here my code.

    void UpdateFirmware::UpdateHardware(const QString hexFileName) {
    	QProcess process;
    	process.setReadChannel(QProcess::StandardOutput);
    	process.setReadChannelMode(QProcess::MergedChannels);
    	QStringList arguments;
    	arguments << "-mmcu=mk20dx256" << "-wv" << hexFileName;
    	process.start("teensy_loader_cli", arguments);
    	process.waitForStarted(1000);
    	process.waitForFinished();
    }
    

    It is working perfectly with Windows system, and exe installer. But it is not working perfectly on MAC System.

    If I will open code in Qt (MAC OS), and run code then I am able to update the firmware from software. After that, I create bundle and place teensy_loader_cli at SquidStat.app->Contents->MacOs->teensy_loader_cli. Now if I will open software from bundle then it is not updating firmware.

    I tested with terminal teensy_loader_cli is work fine.
    what is change do I require in code for make it work?

    R J 2 Replies Last reply 17 Apr 2019, 17:53
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 17 Apr 2019, 17:51 last edited by
      #2

      Hi
      Check out if it returns an error

      connect(&process, &QProcess::errorOccurred, [=](QProcess::ProcessError error) 
      { 
          qDebug() << "error enum val = " << error << endl; 
      });
      
      1 Reply Last reply
      2
      • Y Yash001
        17 Apr 2019, 17:33

        Hi,

        I am using Qt 5.11.0. and MAC system. I am trying to call another software with help of QProcess.

        Here my code.

        void UpdateFirmware::UpdateHardware(const QString hexFileName) {
        	QProcess process;
        	process.setReadChannel(QProcess::StandardOutput);
        	process.setReadChannelMode(QProcess::MergedChannels);
        	QStringList arguments;
        	arguments << "-mmcu=mk20dx256" << "-wv" << hexFileName;
        	process.start("teensy_loader_cli", arguments);
        	process.waitForStarted(1000);
        	process.waitForFinished();
        }
        

        It is working perfectly with Windows system, and exe installer. But it is not working perfectly on MAC System.

        If I will open code in Qt (MAC OS), and run code then I am able to update the firmware from software. After that, I create bundle and place teensy_loader_cli at SquidStat.app->Contents->MacOs->teensy_loader_cli. Now if I will open software from bundle then it is not updating firmware.

        I tested with terminal teensy_loader_cli is work fine.
        what is change do I require in code for make it work?

        R Offline
        R Offline
        raven-worx
        Moderators
        wrote on 17 Apr 2019, 17:53 last edited by
        #3

        @Yash001
        what does QProcess::errorString() return? I guess it can't find teensy_loader_cli, unless its globally available?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        3
        • Y Yash001
          17 Apr 2019, 17:33

          Hi,

          I am using Qt 5.11.0. and MAC system. I am trying to call another software with help of QProcess.

          Here my code.

          void UpdateFirmware::UpdateHardware(const QString hexFileName) {
          	QProcess process;
          	process.setReadChannel(QProcess::StandardOutput);
          	process.setReadChannelMode(QProcess::MergedChannels);
          	QStringList arguments;
          	arguments << "-mmcu=mk20dx256" << "-wv" << hexFileName;
          	process.start("teensy_loader_cli", arguments);
          	process.waitForStarted(1000);
          	process.waitForFinished();
          }
          

          It is working perfectly with Windows system, and exe installer. But it is not working perfectly on MAC System.

          If I will open code in Qt (MAC OS), and run code then I am able to update the firmware from software. After that, I create bundle and place teensy_loader_cli at SquidStat.app->Contents->MacOs->teensy_loader_cli. Now if I will open software from bundle then it is not updating firmware.

          I tested with terminal teensy_loader_cli is work fine.
          what is change do I require in code for make it work?

          J Offline
          J Offline
          J.Hilk
          Moderators
          wrote on 17 Apr 2019, 18:06 last edited by
          #4

          @Yash001 is teensy_loader_cli it’s own appbundle, or did you extract the executable out of it?

          if it‘s an app bundle than your path is wrong.
          From my experience QProcess doesn‘t execute the bundle, you have to go into the contents

          e.g
          teensy_loader_cli.app/Contents/MacOS/teensy_loader_cli


          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          Y 1 Reply Last reply 17 Apr 2019, 18:23
          5
          • Y Offline
            Y Offline
            Yash001
            wrote on 17 Apr 2019, 18:07 last edited by
            #5

            @mrjj @raven-worx

            It is returning QProcess::FailedToStart.

            R 1 Reply Last reply 17 Apr 2019, 18:08
            0
            • Y Yash001
              17 Apr 2019, 18:07

              @mrjj @raven-worx

              It is returning QProcess::FailedToStart.

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 17 Apr 2019, 18:08 last edited by raven-worx
              #6

              @Yash001 said in why QProcess is not working in MAC os?:

              It is returning QProcess::FailedToStart.

              well, you already know that ;)
              I said errorString(), for the sake of a more readable error message

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              Y 1 Reply Last reply 17 Apr 2019, 18:18
              1
              • R raven-worx
                17 Apr 2019, 18:08

                @Yash001 said in why QProcess is not working in MAC os?:

                It is returning QProcess::FailedToStart.

                well, you already know that ;)
                I said errorString(), for the sake of a more readable error message

                Y Offline
                Y Offline
                Yash001
                wrote on 17 Apr 2019, 18:18 last edited by
                #7

                @raven-worx

                Qprocess::errorString() is return "execvp: No such file or directory".

                1 Reply Last reply
                0
                • J J.Hilk
                  17 Apr 2019, 18:06

                  @Yash001 is teensy_loader_cli it’s own appbundle, or did you extract the executable out of it?

                  if it‘s an app bundle than your path is wrong.
                  From my experience QProcess doesn‘t execute the bundle, you have to go into the contents

                  e.g
                  teensy_loader_cli.app/Contents/MacOS/teensy_loader_cli

                  Y Offline
                  Y Offline
                  Yash001
                  wrote on 17 Apr 2019, 18:23 last edited by Yash001
                  #8

                  @J.Hilk
                  It is executable file. it is not bundle. I am not able to do cd teensy_loader_cli.app/Contents/MacOS

                  J 1 Reply Last reply 17 Apr 2019, 18:33
                  0
                  • Y Yash001
                    17 Apr 2019, 18:23

                    @J.Hilk
                    It is executable file. it is not bundle. I am not able to do cd teensy_loader_cli.app/Contents/MacOS

                    J Offline
                    J Offline
                    J.Hilk
                    Moderators
                    wrote on 17 Apr 2019, 18:33 last edited by
                    #9

                    @Yash001 in that case I would suggest opening a QDir instance, on using the entryList function to check if your file is actually there, and if you're actually where you think you are on the file system ;-)


                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                    Q: What's that?
                    A: It's blue light.
                    Q: What does it do?
                    A: It turns blue.

                    Y 1 Reply Last reply 17 Apr 2019, 18:41
                    1
                    • J J.Hilk
                      17 Apr 2019, 18:33

                      @Yash001 in that case I would suggest opening a QDir instance, on using the entryList function to check if your file is actually there, and if you're actually where you think you are on the file system ;-)

                      Y Offline
                      Y Offline
                      Yash001
                      wrote on 17 Apr 2019, 18:41 last edited by Yash001
                      #10

                      @J.Hilk As per my understanding you are talking about to verify the hexfileFile. Is it there or not. Right?

                      In my case I am selecting the hexFileName file manually from GUI.

                      // on click of HexFile button 
                      	m_connections << QObject::connect(hexFilePbt, &QPushButton::clicked, [=]() {
                      
                      		// open the file path which is strore into the SQUID_STAT_PARAMETERS_INI file
                      		QSettings settings(SQUID_STAT_PARAMETERS_INI, QSettings::IniFormat);
                      		QString dirName = settings.value(FW_HEX_OPEN_PATH, "").toString();
                      
                      		QString filePath = QFileDialog::getOpenFileName(frame, "Select firmware file", dirName, "Intel HEX (*.hex)");
                      
                      		if (filePath.isEmpty()) {
                      			return;
                      		}
                      
                      		settings.setValue(FW_HEX_OPEN_PATH, QFileInfo(filePath).absolutePath());
                      		hexFileLed->setText(filePath);
                      	});
                      
                      1 Reply Last reply
                      0
                      • Y Offline
                        Y Offline
                        Yash001
                        wrote on 17 Apr 2019, 18:49 last edited by
                        #11

                        Is it any way to determine the what is input string to terminal while using QProcess.

                        When I manually load firmware at that time my input is
                        ./teensy_loader_cli -mmcu=mk20dx256 -wv "/Users/Computer/Desktop/Frimware/3.Squidstat prime firmware Mar 06 2019 (copy) with autoreset.hex"

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 17 Apr 2019, 18:51 last edited by
                          #12

                          Hi,

                          Where is that executable located on your machine ?

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

                          Y 1 Reply Last reply 17 Apr 2019, 18:57
                          0
                          • SGaistS SGaist
                            17 Apr 2019, 18:51

                            Hi,

                            Where is that executable located on your machine ?

                            Y Offline
                            Y Offline
                            Yash001
                            wrote on 17 Apr 2019, 18:57 last edited by Yash001
                            #13

                            @SGaist
                            I am compiling full code in Qt and after that I am adding all dependency of SquidStat.app with help of shell script.

                            In shell script, I copy my teensy_loader_cli executable file from machine location to SquidStat.app/Contents/MacOS/.

                            If I will call SquidStat.app from the Qt run button at that time it is work. But I will go at output dir, and click on SquidStat.app. It is open SquidStat.app software but Updating firmware functionality is not working.

                            In general, executable file is located at location SquidStat.app/Contents/MacOS/

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on 17 Apr 2019, 20:20 last edited by
                              #14

                              Then you should use QCoreApplication::applicationDirPath to build the path to that executable.

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

                              Y 1 Reply Last reply 17 Apr 2019, 21:13
                              3
                              • SGaistS SGaist
                                17 Apr 2019, 20:20

                                Then you should use QCoreApplication::applicationDirPath to build the path to that executable.

                                Y Offline
                                Y Offline
                                Yash001
                                wrote on 17 Apr 2019, 21:13 last edited by
                                #15

                                Thank you @SGaist for guidance. application is not able to find the correct location of teensy_loader_cli.

                                Now, I am able get correct functionality with help QCoreApplication::applicationDirPath()

                                Here modify code, and It is work.

                                void UpdateFirmware::UpdateHardware(const QString hexFileName) {
                                	QProcess process;
                                	process.setReadChannel(QProcess::StandardOutput);
                                	process.setReadChannelMode(QProcess::MergedChannels);
                                	QStringList arguments;
                                	arguments << "-mmcu=mk20dx256" << "-wv" << hexFileName;
                                	auto program = QCoreApplication::applicationDirPath() +"/"+QString("teensy_loader_cli");
                                        process.start(program, arguments);
                                	process.waitForStarted(1000);
                                	process.waitForFinished();
                                }
                                

                                I have one last question if I will add QThread thread; process.moveToThread(&thread) then Process will be start on separate thread. Right?

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on 17 Apr 2019, 21:26 last edited by
                                  #16

                                  If you want UpdateHardware to not block your GUI, then you should rather take advantage of QProcess's asynchronous nature rather than involving threads.

                                  What exactly do you want to achieve ?

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

                                  Y 1 Reply Last reply 17 Apr 2019, 21:57
                                  2
                                  • SGaistS SGaist
                                    17 Apr 2019, 21:26

                                    If you want UpdateHardware to not block your GUI, then you should rather take advantage of QProcess's asynchronous nature rather than involving threads.

                                    What exactly do you want to achieve ?

                                    Y Offline
                                    Y Offline
                                    Yash001
                                    wrote on 17 Apr 2019, 21:57 last edited by Yash001
                                    #17

                                    @SGaist

                                    I am trying to update the firmware in hardware with help of teensy_loader_cli. teensy_loader_cli loader need reset signal before updating firmware.

                                    case 1:
                                    If hardware received reset signal from software before QProcess is start then QProcess will not block (teensy_loader_cli will not block the process). It is execute.

                                    case 2:
                                    If hardware received reset signal from software after QProcess is start then QProcess will block (teensy_loader_cli will block the process) until reset signal is received from software.

                                    Reset signal is always call before process is start, But Signal is not received immediately in hardware (code is little messy, I will make it clean)
                                    0_1555537882072_91b9191e-7d68-47dc-83c5-90f9486b930b-image.png

                                    In both case User will not access the other functionality of Software. For blocking functionality I am using one dialog boxauto dialog = new QDialog(parent, Qt::SplashScreen). which is give update regrading firmware. Once firmware update is done after that User will get the OK button on dialog box. By click on OK button dialog box will be close and User will get all other access.

                                    So I am thinking about to start QProcess on separate thread and give update to GUI regrading firmware update through signals like emit BootloaderStarted(); emit BootloaderFound();emit BootloaderSetProgress(100);emit BootloaderFinished(true);.

                                    JonBJ 1 Reply Last reply 17 Apr 2019, 22:33
                                    0
                                    • Y Yash001
                                      17 Apr 2019, 21:57

                                      @SGaist

                                      I am trying to update the firmware in hardware with help of teensy_loader_cli. teensy_loader_cli loader need reset signal before updating firmware.

                                      case 1:
                                      If hardware received reset signal from software before QProcess is start then QProcess will not block (teensy_loader_cli will not block the process). It is execute.

                                      case 2:
                                      If hardware received reset signal from software after QProcess is start then QProcess will block (teensy_loader_cli will block the process) until reset signal is received from software.

                                      Reset signal is always call before process is start, But Signal is not received immediately in hardware (code is little messy, I will make it clean)
                                      0_1555537882072_91b9191e-7d68-47dc-83c5-90f9486b930b-image.png

                                      In both case User will not access the other functionality of Software. For blocking functionality I am using one dialog boxauto dialog = new QDialog(parent, Qt::SplashScreen). which is give update regrading firmware. Once firmware update is done after that User will get the OK button on dialog box. By click on OK button dialog box will be close and User will get all other access.

                                      So I am thinking about to start QProcess on separate thread and give update to GUI regrading firmware update through signals like emit BootloaderStarted(); emit BootloaderFound();emit BootloaderSetProgress(100);emit BootloaderFinished(true);.

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on 17 Apr 2019, 22:33 last edited by
                                      #18

                                      @Yash001
                                      You should not need to run a QProcess in a separate thread. Instead, do not call waitForStarted()/waitForFinished() as you show, rather use the QProcess::finished etc. signals. That is what @SGaist was indicating when he said:

                                      take advantage of QProcess's asynchronous nature rather than involving threads

                                      Y 1 Reply Last reply 17 Apr 2019, 23:00
                                      4
                                      • JonBJ JonB
                                        17 Apr 2019, 22:33

                                        @Yash001
                                        You should not need to run a QProcess in a separate thread. Instead, do not call waitForStarted()/waitForFinished() as you show, rather use the QProcess::finished etc. signals. That is what @SGaist was indicating when he said:

                                        take advantage of QProcess's asynchronous nature rather than involving threads

                                        Y Offline
                                        Y Offline
                                        Yash001
                                        wrote on 17 Apr 2019, 23:00 last edited by Yash001
                                        #19

                                        @JonB Thank you for correct direction. I will modify my code and use it finished Signal for updating dialog box.

                                        1 Reply Last reply
                                        1

                                        1/19

                                        17 Apr 2019, 17:33

                                        • Login

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