[Solved] How to run gcc compiler from my qt application? [closed]


You can run any program from Qt5 and capture it’s standard output using the QProcess class. The official documentation with examples is here: http://doc.qt.io/qt-5/qprocess.html

So what I would do then is simply make a GUI with 2 QTextEdit widgets, one for the code and one for the compile/run output. Documentation for QTextEdit is here: http://doc.qt.io/qt-5/qtextedit.html

So the “compile and run” button would simply

  1. Take content of upper QTextEdit into a temporary text file on disk. Documentation for QFile is here: http://doc.qt.io/qt-5/qfile.html
  2. Start gcc to complie the file using QProcess and capture the output in a string
  3. Replace the content of the bottom QTextEdit with the output of the compilation.
  4. Look at return code from QProcess to see if compilation was successful.
  5. For successful build, simply invoke QProcess again, this time for the executable that was built by gcc to run the code, while appending any output to the bottom QTextEdit.

NOTE: As an exercise this is probably going to be fun and provide ample opportunity for learning, however I doubt this would be very useful on its own.

Good luck!

solved How to run gcc compiler from my qt application? [closed]