Results 1 to 3 of 3

Thread: Why this code doesn't work?

  1. #1
    Join Date
    Jan 2009
    Posts
    29
    Qt products
    Qt4
    Platforms
    Unix/X11

    Arrow Why this code doesn't work?

    Qt version: 4.4.3.

    OS: Ubuntu Linux Desktop Edition 8.10 x86.

    The following code does not insert the "ls -hal" output to the QTextEdit object. The QTextEdit object appears empty. Why?

    A screenshot is attached.

    Qt Code:
    1. #include <QApplication>
    2. #include <QDialog>
    3. #include <QProcess>
    4. #include "ui_qsysv-rc-conf.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9.  
    10. Ui::Dialog ui;
    11.  
    12. QDialog *dialog= new QDialog;
    13.  
    14. ui.setupUi(dialog);
    15.  
    16. dialog->show();
    17.  
    18.  
    19. QProcess *sysvProcess = new QProcess(dialog);
    20.  
    21. sysvProcess->start("ls -hal");
    22.  
    23. const QByteArray &input= sysvProcess->readAllStandardOutput();
    24.  
    25. ui.textEdit->setText(QString(input));
    26.  
    27.  
    28. app.exec();
    29.  
    30. return 0;
    31. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  2. #2
    Join Date
    Nov 2008
    Location
    Italy
    Posts
    16
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why this code doesn't work?

    Try use QProcess::waitForFinished maybe your QProcess sysvProcess has not alreasy written anything to stdoutput when you call readAllStandardOutput().

  3. #3
    Join Date
    Aug 2008
    Location
    Porto Alegre
    Posts
    65
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Why this code doesn't work?

    try something like this:

    Qt Code:
    1. QString prog = "/bin/bash";
    2. QStringList arguments;
    3. arguments << "-c" << "ls -hal";
    4. QProcess* process = new QProcess(this);
    5. process->start(prog , arguments);
    6. process->waitForFinished();
    7.  
    8. QString tmp = process->readAll();
    9. qDebug() << tmp;
    10. ui.textEdit->setText(tmp);
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Qt4 : QPainter::setRedirected doesn't work
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 20th June 2008, 17:52
  2. Objective C, Python and Ruby code with C++ Qt application
    By Berberis in forum Qt Programming
    Replies: 2
    Last Post: 5th June 2008, 12:40
  3. Qt 4.3.0 lots of Bugs!
    By VireX in forum Qt Programming
    Replies: 69
    Last Post: 20th June 2007, 22:05
  4. Qt Cryptographic Architecture
    By vermarajeev in forum Qt Programming
    Replies: 6
    Last Post: 9th February 2007, 13:15
  5. Mac Port of Windows code
    By Nemo in forum Qt Programming
    Replies: 2
    Last Post: 13th February 2006, 07:37

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.