Results 1 to 3 of 3

Thread: Text from standart output

  1. #1
    Join Date
    May 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Text from standart output

    I am use readAllStandardOutput(), but it not get text from outpt (work only with "ping" or "ipconfig").
    If i start with CMD (whout my programm) i can see text in console. But from my code to string put "".
    Please help
    .H
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include "ui_mainwindow.h"
    5. #include <QProcess>
    6.  
    7. class MainWindow : public QMainWindow, private Ui::MainWindow
    8. {
    9. Q_OBJECT
    10.  
    11. public:
    12. explicit MainWindow(QWidget *parent = 0);
    13. QProcess *myprocess;
    14. private slots:
    15. void on_pushButton_clicked();
    16. void outExec();
    17. void finishExec ( int exitCode, QProcess::ExitStatus exitStatus );
    18. };
    19.  
    20. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    .CPP
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QDebug>
    3. #include <QDir>
    4.  
    5. MainWindow::MainWindow(QWidget *parent) :
    6. QMainWindow(parent)
    7. {
    8. setupUi(this);
    9. }
    10.  
    11. void MainWindow::on_pushButton_clicked()
    12. {
    13. QString programm = lineEdit->text();
    14. myprocess = new QProcess(this);
    15. myprocess->setObjectName(programm);
    16. //don`t work
    17. //myprocess->start(QString("exec\\" + programm).toAscii());
    18. //don`t work too
    19. myprocess->start(QString("cmd /C " + QDir::currentPath() + "/exec/" + programm).toAscii());[ATTACH]8883[/ATTACH]
    20. qDebug() << "RUN " << QString("cmd /C " + QDir::currentPath() + "/exec/" + programm).toAscii();
    21. connect(myprocess, SIGNAL(readyReadStandardOutput ()), this, SLOT(outExec()));
    22. connect(myprocess, SIGNAL(finished (int,QProcess::ExitStatus)), this, SLOT(finishExec(int,QProcess::ExitStatus)));
    23. }
    24.  
    25. void MainWindow::outExec()
    26. {
    27. QString out = myprocess->readAllStandardOutput();
    28. qDebug() << "__" << out;
    29. plainTextEdit->appendPlainText(QString(out));
    30. }
    31.  
    32. void MainWindow::finishExec ( int exitCode, QProcess::ExitStatus exitStatus )
    33. {
    34. QString out = myprocess->readAllStandardOutput();
    35. qDebug() << out;
    36. plainTextEdit->appendPlainText(QString(out));
    37. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Text from standart output

    Start the program directly instead.

    Qt Code:
    1. //myprocess->start(QString("cmd /C " + QDir::currentPath() + "/exec/" + programm).toAscii());
    2. myprocess->start(QString(QDir::currentPath() + "/exec/" + programm).toAscii());
    To copy to clipboard, switch view to plain text mode 
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Text from standart output

    Any specific reason do not run the program directly?

    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 22nd September 2012, 01:18
  2. QT Output Text
    By Johnnyj2j in forum Newbie
    Replies: 1
    Last Post: 7th August 2012, 16:12
  3. I don't get expected output in text browser
    By NewLegend in forum Qt Programming
    Replies: 14
    Last Post: 25th July 2010, 09:21
  4. output while executing should be redirected to text file
    By AnithaRagupathy in forum Qt Programming
    Replies: 3
    Last Post: 13th October 2007, 10:33
  5. Replies: 52
    Last Post: 10th December 2006, 14:32

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.