How to run gcc compiler from my qt application? [closed] - c++

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
1- I am working on a project and i have made a simple GUI but i want to make a run button in my GUI to compile and run c code ??
(i want to make simple ide so i used qt to make my ui but i can not make a button which send arg to windows terminal )
2- How to have a good start with Qt (need a good tutorial)

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
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
Start gcc to complie the file using QProcess and capture the output in a string
Replace the content of the bottom QTextEdit with the output of the compilation.
Look at return code from QProcess to see if compilation was successful.
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!

Related

Is there a way to have a C or C++ program open a new terminal window and start executing code for you? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 months ago.
Improve this question
I want to create a C or C++ program that automates some things for me.
The idea is as such: I run the program ./a.out and sit back and watch as it opens up three or four new terminal windows and runs various UNIX commands. Is there a way to do this?
I am on a MacBook.
As the comments point out, this is probably best accomplished by a shell script. However, you can execute shell commands from C with the system(3) standard library function. To open a terminal, just run a terminal with a particular command. For example:
system("xterm -e 'echo hello; sleep 5'");

Limited .exe Output in C++ [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
I'm sure this is a simple question, but I tried a couple google searches and wasn't sure what keywords to search.
After executing my program in C++ the .exe window that opens is only showing the bottom part of my output, while cutting off the top. Any thoughts on how to view all of my output?
Thank you.
You can redirect the output of the program to a file:
your-program.exe > file.txt
Alternatively, you can pipe the output into more:
your-program.exe | more
This will pause the output of your program when it fills one screen until you press the space bar.
Both approaches have their pros and cons: if you redirect the output to file and open that file while the program is running, you might not see the last chunk of data, because the OS might buffer the data before writing it to hard disk.
If you pipe the output into more then the execution of your program might be suspended while more is waiting for your input.
[Edit: incorporated enhzflep's suggestion of using a redirection to a file.]
suppose you have an "a.exe" program
execute the program like this:
a.exe >1.txt
and open the file "1.txt" with notepad or other editor(such as notepad++).

Install a program from another program [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I'm a game developer and my current task is to create a game launcher. If you know what is Battle.net, you'll understand what I mean. For the launcher itself we're using the InstallBuilder from Bitrock. But the end user should have a possibility to install actual game pressing a button in the launcher. The launcher then will download files, register them, show progress bar, allow to play a game before full download, create a shortcut etc. - the same way as Battle.net launcher behave.
So, my question - where to start? I suppose that this is platform specific, so for now I'm interested in Windows. I'm using VS2013, Qt.
First of all, you must create an installer which will handle the actual installation of the application. You can then call the installer from your other process (in your case the launcher.)
In Qt you can use the QProcess Class which is documented here. I think that the documentation is really good and will answer most of your questions but what you need to do more or less is this:
QObject *parent;
...
QString program = "./path/to/your/installer";
QStringList arguments;
arguments << "-option" << "argument";
QProcess *myProcess = new QProcess(parent);
myProcess->start(program, arguments);
(Copied pretty much verbatim for the documentation.)
You also have the option of interacting with your installer after its execution start (you can for example read the exit code) so that you can monitor the installation progress form your launcher.

pass data from a python application to a running c++ application [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I coded to applications one in python the other one in c++. In the middle of the python app I need to run the c++ app pass some input to it and receive the output. I already know that I can call the c++ app from python using subprocess but since that c++ app has to do some initial calculations each time it is called it makes my program really slow. So what I was looking for is this:
put my c++ app in an infinite while loop and keep it running. Then in my python app whenever I need a call to the c++ app just pass the data and get the output. This way i can avoid repeating the initial state every time I need to make this call.
Is there anyway to do this? Like writing another application that controls all of these. Also there can be multiple instances of the python app running but I want to have just one of the c++ app running since it takes a lot of memory
Using subprocess.Popen you can open a process and keep it open, use the stdin and stdout to communicate with it. When you open the process use: stdout=subprocess.PIPE, stdin=subprocess.PIPE .
You can then write to process.stdin and read from process.stdout the output of the c++ program.
You can do it with boost python. Design a class that perform the initial computation in its constructor and a method to perform the computation. You wrap it and instantiate it from python once.
subprocess solution is possible too, as asafpr answered.
You also can set a XML-RPC server in the C++ app and call it from Python with with xmlrpclib module.

How to continue program after another window is opened [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
So I am an amateur programmer, currently enrolled in my second semester of C++ (yesterday we learned about structs just to give you an idea of what I know...).
I am creating a simple program to help me file documents at my internship.
I am using a system command(yes I know its dangerous and a big security risk), to open a pdf in firefox so that I can see the file and know where to put it.
I have successfully opened firefox and opened the pdf.
However my program stops running until I close firefox.
My question is how do I continue my program at the same time?
Is there an easier way to display a pdf in an executable?
edit:
Here is the function I use to open the firefox window with the pdf in it:
void openPDFBrowser (char array[])
{
ofstream outFile;
outFile.close();
outFile.open("PDF_browswer_handleScript.txt") ;
if(outFile.good())cout<<"OUTFILE GOOD" << endl;
outFile << "system("<<array<<")"<<endl;
system("PDF_browswer_handleScript.txt");
outFile.close();
}
the .txt file contails: firefox C:\Scans\Attorney.pdf
where firefox references a .bat file which contains the location of firefox.exe
I will take any suggestions
it just seemed easier to use an external browser to handle the display of the pdf file, although I'm still working out this threading idea
system is a blocking command - meaning it will stop your execution until that function returns. The only way to do this is to create a separate thread (or to fork a separate process, as noted by Chris Hayes), and to run the system (or CreateProcess, or exec) inside it, allowing main thread to continue.