PDA

View Full Version : Read/Write on a konsole from Qt app



Joccy
17th September 2007, 16:35
Hello,
i am new in Qt3 and linux world: so my questions can be stupid for some of you ...sorry :o

I have to do a GUI interface in Qt of a perl programm. So i put a QTextEdit in a window, implement a QProcess, and try to have stdout from konsole to my QTextEdit. And try to write from my app to the konsole.

I try lots of tutorials but without success:


1/In my constructor of window:
myProc = new QProcess(this);

2/in my button click:
myProc->addArgument("konsole");
myProc->addArgument("-e");
myProc->addArgument("pet"); // my exe perl

connect(myProc, SIGNAL(readyReadStdout(), this, SLOT(readFromStdout()));

myProc->start();

3/My slot:
void MyWin::readFromStdout()
{
myTextEdit->append(myProc->readStdout());
}

4/ for writing i use:
myProc->writeToStdin(myString);


The perl app start in a konsole but nothing is read or write in my text edit. Is there someone to help me ? :confused:

Thanks a lot

wysota
17th September 2007, 17:19
Don't use konsole. Call the application directly (or using some interpreter like /bin/sh or /usr/bin/perl).

Joccy
9th October 2007, 12:04
Hello, i'am back !
I do what you told me. It didn't work very well: i have all the help, the errors and so on, in my text edit, but when i try to launch my exe, i only have errors:


Cannot open /dev/tty for read at ... interactive.pm line 273
Compilation failed in require at .../bin/pet line 220
...

but if i launch my exe via "konsole -e", my exe works but i have nothing on my text edit!!

Any ideas ?
thanks a lot

wysota
9th October 2007, 12:21
Looks like the application needs a real terminal. I don't think you'll be able to easily do what you want. The best way would be to modify the app so that it doesn't require /dev/tty but read from its standard input instead. The problem is konsole intercepts everything the application outputs but it doesn't forward it to your application. I guess it could be possible to use the "tee" command to split the output so that it goes to both konsole and some other descriptor which you may catch, but it's tricky. And of course you won't be able to send commands back to the application.

Joccy
9th October 2007, 15:33
Thanks a lot.
I don't know how to do my app, but i have an explanation of why not possible.
thanks again ...

wysota
9th October 2007, 15:50
As I said, try changing the perl program. It probably tries to read some password or something similar from the terminal. Modify it so that it reads it from stdin.

Joccy
12th October 2007, 10:43
Hi !
If i try


myProcess->addArgument("tail");
myProcess->addArgument("/dev/tty");

i have the same pb: it works on konsole and not in my c++ app The error is

Cannot open '/dev/tty' for reading: no such device or address

So is there some flags/variables to be changed ?
(my /dev/tty exist and is crw-rw-rw- mode).
Thanks

wysota
12th October 2007, 12:29
But what do you expect from me? You don't have a terminal attached to your application, so you can't access /dev/tty from it. You have to change the application so that it doesn't use the terminal or find some other way to communicate with the application (but that requires changing it as well).

jacek
12th October 2007, 15:10
Maybe this will help: http://labs.trolltech.com/blogs/2006/03/16/starting-interactive-processes-with-qprocess/

Joccy
4th February 2008, 13:21
Thanks a lot.
I'am back to explain what i did: i modified perl file:



$term = new Term::ReadLine ('name', \*STDIN, \*STDOUT);


i just had the two last parameters ....

Thanks