Results 1 to 3 of 3

Thread: textBrowser not show anything

  1. #1
    Join Date
    Apr 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Angry textBrowser not show anything

    Why codes are not running. There is not any affect on textBrowser...?



    #include <QProcess>
    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow:n_exit_clicked()
    {
    this->close();
    }

    void MainWindow:n_button_clicked()
    {
    QProcess *p = new QProcess( this );

    if (p)
    {
    p->setEnvironment( QProcess::systemEnvironment() );
    p->setProcessChannelMode( QProcess::MergedChannels );
    connect( p, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadOut()) );
    connect( p, SIGNAL(readyReadStandardError()), this, SLOT(ReadErr()) );
    p->execute("sh /home/user/Desktop/file.sh");
    p->waitForStarted();


    }
    }

    void MainWindow::ReadOut()
    {

    QProcess *p = dynamic_cast<QProcess *>( sender() );

    if (p)
    ui->textBrowser->append( p->readAllStandardOutput() );
    }

    void MainWindow::ReadErr()
    {

    QProcess *p = dynamic_cast<QProcess *>( sender() );

    if (p)
    ui->textBrowser->append( p->readAllStandardError() );
    }

  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: textBrowser not show anything

    Use QProcess::start(), instead of QProcess::execute().

    Qt Code:
    1. void MainWindow::on_button_clicked()
    2. {
    3. QProcess *p = new QProcess( this );
    4.  
    5. if (p)
    6. {
    7. p->setEnvironment( QProcess::systemEnvironment() );
    8. p->setProcessChannelMode( QProcess::MergedChannels );
    9. connect( p, SIGNAL(readyReadStandardOutput()), this, SLOT(ReadOut()) );
    10. connect( p, SIGNAL(readyReadStandardError()), this, SLOT(ReadErr()) );
    11. //p->execute("sh /home/user/Desktop/file.sh");
    12. p->start("sh /home/user/Desktop/file.sh");
    13. p->waitForStarted();
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    QProcess::execute(), is a static call and will start another new process (which is not p), you actualy need to connect to the signals of the new process created in side execute() function, but you cannot access it.
    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
    Apr 2013
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Red face Re: textBrowser not show anything

    Thank you very much...

Similar Threads

  1. how to scroll a textbrowser ?
    By kumari arpita in forum Newbie
    Replies: 2
    Last Post: 10th August 2012, 08:56
  2. Time in textBrowser
    By NewLegend in forum Qt Programming
    Replies: 13
    Last Post: 12th October 2010, 04:37
  3. space in textBrowser
    By NewLegend in forum Qt Programming
    Replies: 4
    Last Post: 3rd September 2010, 19:04
  4. New Line in textBrowser
    By NewLegend in forum Qt Programming
    Replies: 4
    Last Post: 12th August 2010, 05:29
  5. Textbrowser issue
    By deekayt in forum Qt Programming
    Replies: 1
    Last Post: 29th October 2006, 07:51

Tags for this Thread

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.