Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

why QProcess is not working in MAC os?



  • 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?


  • Lifetime Qt Champion

    Hi
    Check out if it returns an error

    connect(&process, &QProcess::errorOccurred, [=](QProcess::ProcessError error) 
    { 
        qDebug() << "error enum val = " << error << endl; 
    });
    

  • Moderators

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


  • Moderators

    @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



  • @mrjj @raven-worx

    It is returning QProcess::FailedToStart.


  • Moderators

    @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



  • @raven-worx

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



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


  • Moderators

    @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 ;-)



  • @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);
    	});
    


  • 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"


  • Lifetime Qt Champion

    Hi,

    Where is that executable located on your machine ?



  • @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/


  • Lifetime Qt Champion

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



  • 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?


  • Lifetime Qt Champion

    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 ?



  • @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);.



  • @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



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