Results 1 to 2 of 2

Thread: QProcess and Qtextedit problem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Posts
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QProcess and Qtextedit problem

    Hi All ,

    First of all let me explain what I am tring to achive here

    "I am tring to update the output of the Qprocess which runs the perl script to a textEdit"
    Which should look like qprocess is updateing it runtime.


    Please find some of the main code





    #include <QtGui>

    #include "testcasefm.h"


    testCaseFm::testCaseFm( QWidget * parent ): QWidget( parent ),scriptProcess(NULL)
    {
    setupUi(this);
    counter =0 ;
    scriptProcess = new QProcess( this );
    scriptProcess->setProcessChannelMode(QProcess::MergedChannels) ;
    label_targetName->setFocus();

    testCaseFm::init();
    //connect(label_targetName ,SIGNAL(setFocus()),this,SLOT(init()));
    connect(pushButton_openScript ,SIGNAL(clicked()),this,SLOT(pB_openScript()));
    connect(pushButton_runScript ,SIGNAL(clicked()),this,SLOT(pB_runScript()));
    connect(pushButton_stopScript ,SIGNAL(clicked()),this,SLOT(pB_stopScript()));
    connect(pushButton_closeTestcasefm ,SIGNAL(clicked()),this,SLOT(pB_close()));
    connect(scriptProcess ,SIGNAL(readyReadStandardOutput()),this,SLOT(updat eOutputTextEdit()));
    connect(scriptProcess ,SIGNAL(readyReadStandardError()),this,SLOT(update ErrorOutputTextEdit()));
    connect(scriptProcess ,SIGNAL(finished(int, QProcess::ExitStatus)),this,SLOT(processFinished(i nt, QProcess::ExitStatus)));
    connect(scriptProcess ,SIGNAL(error(QProcess::ProcessError)),this,SLOT(p rocessError(QProcess::ProcessError)));

    }

    testCaseFm::~testCaseFm()
    {
    close();
    qDebug() << counter;
    }
    odes
    The method which updates the textedit

    void testCaseFm::updateOutputTextEdit()
    {
    // scriptProcess->setReadChannel(QProcess::StandardOutput);
    QByteArray newData = scriptProcess->readAllStandardOutput();
    QString text = textEdit->toPlainText()
    +QString::fromLocal8Bit(newData);
    textEdit->append(text);
    counter++;


    }


    void testCaseFm::updateErrorOutputTextEdit()
    {
    // textEdit->append("----------Stard Error---------");
    // scriptProcess->setReadChannel(QProcess::StandardError);
    QByteArray newData = scriptProcess->readAllStandardError();
    QString text_error = textEdit->toPlainText()
    +QString::fromLocal8Bit(newData);
    textEdit->append(text_error);
    }

    The output which I am getting from the Qprocess

    /dev/nst

    /dev/nst

    /dev/nst

    /dev/nst

    /dev/nst

    /dev/nst

    /dev/nst
    FEWrite_diags_port2000_1
    /dev/nst: No such file or directory
    /dev/nst: No such file or directory
    dd: opening `/root/logs/FEWrite_diags_port2000_1': No such file or directory


    The actual out put when I run the script on the linbux box

    /dev/nst
    FEWrite_diags_port2000_1
    /dev/nst: No such file or directory
    /dev/nst: No such file or directory
    dd: opening `/root/logs/FEWrite_diags_port2000_1': No such file or directory


    I suspect the output method is going into loop but I dont know why ...

    I would appricate any suggestion ...plz

    One more thing i wanted to know is " can I update the textedit which is in main thread
    sing new thread ".
    Attached Files Attached Files

Similar Threads

  1. QProcess and Pipes
    By KaptainKarl in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2007, 23:11
  2. problem with QProcess in Qt4
    By kennyxing in forum Qt Programming
    Replies: 4
    Last Post: 20th October 2006, 09:07

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
  •  
Qt is a trademark of The Qt Company.