Results 1 to 10 of 10

Thread: Read/Write on a konsole from Qt app

  1. #1
    Join Date
    Sep 2007
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Question Read/Write on a konsole from Qt app

    Hello,
    i am new in Qt3 and linux world: so my questions can be stupid for some of you ...sorry

    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:
    Qt Code:
    1. 1/In my constructor of window:
    2. myProc = new QProcess(this);
    3.  
    4. 2/in my button click:
    5. myProc->addArgument("konsole");
    6. myProc->addArgument("-e");
    7. myProc->addArgument("pet"); // my exe perl
    8.  
    9. connect(myProc, SIGNAL(readyReadStdout(), this, SLOT(readFromStdout()));
    10.  
    11. myProc->start();
    12.  
    13. 3/My slot:
    14. void MyWin::readFromStdout()
    15. {
    16. myTextEdit->append(myProc->readStdout());
    17. }
    18.  
    19. 4/ for writing i use:
    20. myProc->writeToStdin(myString);
    To copy to clipboard, switch view to plain text mode 

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

    Thanks a lot

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Read/Write on a konsole from Qt app

    Don't use konsole. Call the application directly (or using some interpreter like /bin/sh or /usr/bin/perl).

  3. #3
    Join Date
    Sep 2007
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Read/Write on a konsole from Qt app

    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
    Last edited by wysota; 9th October 2007 at 11:17. Reason: Changed [code] into [quote]

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Read/Write on a konsole from Qt app

    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.

  5. #5
    Join Date
    Sep 2007
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Read/Write on a konsole from Qt app

    Thanks a lot.
    I don't know how to do my app, but i have an explanation of why not possible.
    thanks again ...

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Read/Write on a konsole from Qt app

    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.

  7. #7
    Join Date
    Sep 2007
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Read/Write on a konsole from Qt app

    Hi !
    If i try
    Qt Code:
    1. myProcess->addArgument("tail");
    2. myProcess->addArgument("/dev/tty");
    To copy to clipboard, switch view to plain text mode 
    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

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Read/Write on a konsole from Qt app

    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).

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Read/Write on a konsole from Qt app


  10. #10
    Join Date
    Sep 2007
    Posts
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Thumbs up Re: Read/Write on a konsole from Qt app

    Thanks a lot.
    I'am back to explain what i did: i modified perl file:

    Qt Code:
    1. $term = new Term::ReadLine ('name', \*STDIN, \*STDOUT);
    To copy to clipboard, switch view to plain text mode 

    i just had the two last parameters ....

    Thanks

  11. The following user says thank you to Joccy for this useful post:

    jacek (4th February 2008)

Similar Threads

  1. How to read/write PDF file from Qt Application?
    By rajesh in forum Qt Programming
    Replies: 5
    Last Post: 30th August 2007, 08:39
  2. dislplay info in konsole?
    By lum in forum KDE Forum
    Replies: 1
    Last Post: 27th April 2006, 16:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.