PDA

View Full Version : Re: Quick help on QProcess



ufo-vl
25th July 2007, 08:06
I think is valid:


out->append(process.readAllStandardOutput());


I'm try create simple application when using QProcess class,
but I didn't receive output buffer.



//main.cpp
#include <QApplication>
#include "dialogimpl.h"
//
int main(int argc, char ** argv)
{
QApplication app( argc, argv );
DialogImpl win;
win.show();
app.connect( &app, SIGNAL( lastWindowClosed() ), &app, SLOT( quit() ) );
return app.exec();
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
// dialogimpl.cpp
#include "dialogimpl.h"
#include <QProcess>
//
DialogImpl::DialogImpl( QWidget * parent, Qt::WFlags f)
: QDialog(parent, f)
{
setupUi(this);
process = new QProcess(this);
process->setReadChannel(QProcess::StandardOutput);
connect(process, SIGNAL(readyReadStandardOutput()), this, SLOT(output()));
connect(pushButton, SIGNAL(clicked()), this, SLOT(runcmd()));
}
//
void DialogImpl::output()
{
textEdit->append((process->readAllStandardOutput()));
}
//
void DialogImpl::runcmd()
{
process->start(lineEdit->text());
}

///////////////////////////////////////////////////////////////////////////////////////////////////////
// dialogimpl.h
#ifndef DIALOGIMPL_H
#define DIALOGIMPL_H
//
#include "ui_dialog.h"
//
class QProcess;

class DialogImpl : public QDialog, public Ui::Dialog
{
Q_OBJECT
public:
DialogImpl( QWidget * parent = 0, Qt::WFlags f = 0 );
private slots:
void output();
void runcmd();
private:
QProcess* process;
};
#endif


Where I was mistaken?

jacek
25th July 2007, 22:16
What happens if you add:
connect( process, SIGNAL(started()), QCoreApplication::instance(), SLOT(aboutQt()) ); at the end of dialog's constructor?

ufo-vl
27th July 2007, 06:25
Strange situation,
if I run "calc.exe" (for example), it's working (calculator running) and About dialog was shown.
If I run "dir", it's not working, and About dialog was not shown.

:eek:

marcel
27th July 2007, 06:45
But dir is not a real application. It is just built in command prompt.
On the other hand, calc is an application and can be a process.

If you want to use command scripting, then use batch files. Execute them like this:
"cmd.exe my_batchFile.bat"

Regards

ufo-vl
27th July 2007, 07:29
It is very a shame to me. I have absolutely forgotten it.:-(.
Many thanks

ufo-vl
27th July 2007, 07:33
And one question,
when started program,
CONSOLE dialog was shown. Can I to get rid of it?
I'm planned run console commands and taking output from console,
but I do not need to be shown the console thus.

marcel
27th July 2007, 07:56
No, I don't think you can do that.
You cannot run cmd without the window.

Regards

ufo-vl
27th July 2007, 08:08
It is a pity.
But the problem not only at use CMD, at start of the program (which uses QProcess) console dialog was shown :-(.

ufo-vl
27th July 2007, 08:19
The question is solved.
A problem in absence of a patch for hands :))