Results 1 to 2 of 2

Thread: QProcess and Qtextedit problem

  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

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QProcess and Qtextedit problem

    1. First of all use CODE tags instead of QUOTE - it's difficult to get through your pasted code now...
    2. What I can see is that when you want to show next part of output you are appending existing text plus new text. So it looks like this:
    You have this in your textEdit
    some text
    and you get from the output string "some different text", Now you are getting the old "some text" adding "some different text" to it and than appending (adding to the end) it to textEdit. The result is:
    some text
    some text
    some different text
    instead of:
    some text
    some different text
    Append means "add to the end" so you can just append new portion of text without copying existing text one more time.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.