You are not logged in.

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Monday, April 9th 2012, 7:55am

how to use QProcess to show tail command output of a log file on QTextEdit Window?

Hi all,

I am new to Qt and C++.I need to show the contents of a log file using tail command on QTextEdit window.For this i am using QProcess,please let me know how to use QProcess to show tail command output of a log file on QTextEdit Window or is there any other way apart from using QProcess? The .cpp and .h code for the same is given below:-



LOGFILE.cpp

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

loadTextFile();

}

void logFile::on_findButton_clicked()
{
QString searchString=ui->lineEdit->text();
ui->logTextEdit->find(searchString,QTextDocument::FindWholeWords);
}

void logFile::loadTextFile()
{
QFile file("/var/log/system.log");
file.open(QIODevice::ReadOnly|QIODevice::Text);

QTextStream in(&file);
//QString line=in.readAll();

QString cmd("tail");
QProcess* process=new QProcess(this);
process->start(QFile::encodeName(cmd).data(),QStringList()<<"-f"<</var/log/sys.log");
process->waitForReadyRead() or waitForFinished;
QString tmp=process->readAll();
qdebug()<<tmp;

file.close();

ui->logTextEdit->setPlainText(tmp);

QTextCursor cursor->logTextEdit->textCursor();
cursor.movePosition(QTextCursor:: Start,QTextCursor::MoveAnchor,1);
}

LOGFILE.h

class logFile:public QMainWindow
{
Q_OBJECT
public:
logFile(QWidget *parent =0);
~logFile();

public slots:

void loadTextFile();

private slots:
void on_findButton_clicked();
};


Here the problem is that i get tailed output but only of the previous command i.e only once the application is closed and reopened ,i can see the output.But i want to see the output then and there.Please help.I don't know where i am going wrong!

2

Wednesday, April 11th 2012, 7:24pm

search this forum for qprocess. I'm sure all questions have been answered.
If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.