QProcess p;

QString str = "powershell.exe C:/Users/86132/Desktop/file/qtProject/IDE_NE/Lightning-Dir/build-Red_Panda_CPP-Desktop_Qt_5_15_2_MinGW_32_bit-Debug/RedPandaIDE/debug/kit/gcc-arm-none-eabi-9_2/bin/arm-none-eabi-gcc -Iuser -Iport -Ibsp/STM32F1xx_HAL_Driver/Inc -Ibsp/STM32F1xx_HAL_Driver/Inc/Legacy -Ibsp/CMSIS/Device/ST/STM32F1xx/Include -Ibsp/CMSIS/Include -Ikernel -Ilib/MALLOC -Ilib/NE_tool -Ilib/timeMeasure -Ilib -DUSE_HAL_DRIVER -DSTM32F103xE -dM -E C:/Users/86132/Desktop/file/qtProject/IDE_NE/Lightning-Dir/build-Red_Panda_CPP-Desktop_Qt_5_15_2_MinGW_32_bit-Debug/RedPandaIDE/debug/kit/tmp/foo1.c | findstr __GNUC__"

p.start();

这里注意:findstr 是windows提供的系统工具,不是QProcess直接用gcc就能执行的,必须得用系统控制台(powershell.exe或者cmd.exe)才能调用。

执行效果为:

QProcess用cmd运行其它进程_qt