Dear visitor, welcome to QtForum.org.
If this is your first visit here, please read the Help. It explains in detail how this page works.
To use all features of this page, you should consider registering.
Please use the registration form, to register here or read more information about the registration process.
If you are already registered, please login here.
Run Terminal commands from QT application
Well I want to give GCC compiler a gui. So i developed a text editor.Now my problem is that the compiler is command line and I don't know how to do back-end coding COMPILE and RUN buttons so that the same commands that i enter in terminal works with that button click. I am new to QT and i figured it out that this can be done with QProcess or system, can anyone help me with this. i need to do something like that in TURBO-C.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
Sir I am having trouble understanding the documentation. How can I write the terminal commands and redirect the output either to the terminal or to a separate window?
redirect output by
|
Source code
|
1
|
connect( qprocessPtr, SIGNAL( readyReadStandardOutput() ), this, SLOT( getOutput() ) );
|
in the slot...
|
Source code
|
1
2
3
4
5
6
|
QByteArray bytes = m_proc->readAllStandardOutput();
QString s;
s.append(bytes);
textOutput->setText(s); // textOutput is some qtextedit
|
write commands...
|
Source code
|
1
2
3
4
|
QString cmd="dir"; // i'm on windows
QByteArray ba = cmd.toLatin1();
proc->write(ba); // proc=QPointer*
proc->write("\n");
|
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
Sir i tried it,but new QTextEdit wont show up.
here is my code.
for setting up the main editor:
setCentralWidget(editor); // editor is the QTextEdit.
setWindowTitle(tr("Untitled.C Deviant-C"));
fileName = "Untitled.C";
This works fine, but when i tried to run the terminal commands and redirect the output to a new QTextEdit, then that is not happening :
void MainWindow::run()
{
QProcess myProcess;
QString program = "gcc";
QStringList arguments;
arguments << file;
myProcess.start(program, arguments);
myProcess.waitForFinished();
QByteArray result = myProcess.readAllStandardOutput ();
const QString all(result);
QFont font1;
font1.setFamily("Courier");
font1.setFixedPitch(true);
font1.setPointSize(10);
font1.setBold(true);
QTextEdit *textOutput;
textOutput = new QTextEdit;
textOutput->setFont(font1);
textOutput->setText(all);
}
it never shows up because you never show it.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
Thank you sir.
Is it possible to make textOutput window belongs to parent, and that another textOutput window cannot be opened before 1st one is closed. If yes then how?
This post has been edited 1 times, last edit by "jack101" (Mar 19th 2012, 2:12pm)
yes. you just need something that knows when to hide() one, and show() the other.
In Qt if a widget has no parent it will be its own window. If a widget has a parent, then it will be positioned inside the parent.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.
got it.
Thanks a lot sir.