Qt-interest Archive, June 2007
QTextEdit
Message 1 in thread
Hi,
I want to read a file into two textEdit at the same time. Firstly, I use
QTextStream::readAll(), but you konw, the second textEdit couldn't read in
any word. I think this is because after the first textEdit read all, the
cursor of the file locate at the end of the file.
Then, I try QTextStream::readLine() and it works. Both the textEdit could
read in the file. But the reading speed is very slow. So this method isn't
approprite also.
Does anyone have a better idea about this?
Attached related codes:
Firstly, I did it this way:
QFile file(fileName);
if(file.open(QFile::ReadOnly))
{
QTextStream in(&file);
firstTextEdit->setPlainText(in.readAll);
secondTextEdit->setPlainText(in.readAll);
file.close();
}
Then I change it to this:
QFile file(fileName);
if(file.open(QFile::ReadOnly))
{
QTextStream in(&file);
firstTextEdit->setPlainText(in.readAll);
secondTextEdit->setPlainText(in.readAll);
file.close();
}
--
[ signature omitted ]
Message 2 in thread
Sorry, last mail the second method has been written incorrectly, and it
should be this:
QFile file(fileName);
if(file.open(QFile::ReadOnly))
{
QTextStream in(&file);
while(!in.atEnd())
{
firstTextEdit->append(in.readLine);
secondTextEdit->append(in.readLine);
}
file.close();
}
2007/6/8, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
>
> Hi,
> I want to read a file into two textEdit at the same time. Firstly, I use
> QTextStream::readAll(), but you konw, the second textEdit couldn't read in
> any word. I think this is because after the first textEdit read all, the
> cursor of the file locate at the end of the file.
> Then, I try QTextStream::readLine() and it works. Both the textEdit could
> read in the file. But the reading speed is very slow. So this method isn't
> approprite also.
> Does anyone have a better idea about this?
> Attached related codes:
> Firstly, I did it this way:
> QFile file(fileName);
> if(file.open(QFile::ReadOnly))
> {
> QTextStream in(&file);
> firstTextEdit->setPlainText(in.readAll);
> secondTextEdit->setPlainText( in.readAll);
> file.close();
> }
> Then I change it to this:
> QFile file(fileName);
> if(file.open(QFile::ReadOnly))
> {
> QTextStream in(&file);
> firstTextEdit->setPlainText(in.readAll);
> secondTextEdit->setPlainText(in.readAll);
> file.close();
> }
>
>
> --
> Best Regards
> Fengli Zhang
--
[ signature omitted ]
Message 3 in thread
do like this you may get desire one
QFile file(fileName);
if(file.open(QFile::ReadOnly))
{
QTextStream in(&file);
while(!in.atEnd())
{
firstTextEdit->append(in.readLine);
}
in.seek(0);
while(!in.atEnd())
{
secondTextEdit->append(in.readLine);
}
file.close();
}
D. Anil kumar
Every success has a story of great failure.
So don’t stop with failure where
Success comes after failure.
----- Original Message -----
From: "张凤丽" <zhangfenglisdu@xxxxxxxxx>
To: "Qt Interest" <qt-interest@xxxxxxxxxxxxx>
Sent: Friday, June 08, 2007 5:00 PM
Subject: Re: QTextEdit
> Sorry, last mail the second method has been written incorrectly, and it
> should be this:
>
> QFile file(fileName);
> if(file.open(QFile::ReadOnly))
> {
> QTextStream in(&file);
> while(!in.atEnd())
> {
> firstTextEdit->append(in.readLine);
> secondTextEdit->append(in.readLine);
> }
>
> file.close();
> }
>
> 2007/6/8, 张凤丽 <zhangfenglisdu@xxxxxxxxx>:
> >
> > Hi,
> > I want to read a file into two textEdit at the same time. Firstly, I use
> > QTextStream::readAll(), but you konw, the second textEdit couldn't read
in
> > any word. I think this is because after the first textEdit read all, the
> > cursor of the file locate at the end of the file.
> > Then, I try QTextStream::readLine() and it works. Both the textEdit
could
> > read in the file. But the reading speed is very slow. So this method
isn't
> > approprite also.
> > Does anyone have a better idea about this?
> > Attached related codes:
> > Firstly, I did it this way:
> > QFile file(fileName);
> > if(file.open(QFile::ReadOnly))
> > {
> > QTextStream in(&file);
> > firstTextEdit->setPlainText(in.readAll);
> > secondTextEdit->setPlainText( in.readAll);
> > file.close();
> > }
> > Then I change it to this:
> > QFile file(fileName);
> > if(file.open(QFile::ReadOnly))
> > {
> > QTextStream in(&file);
> > firstTextEdit->setPlainText(in.readAll);
> > secondTextEdit->setPlainText(in.readAll);
> > file.close();
> > }
> >
> >
> > --
> > Best Regards
> > Fengli Zhang
>
>
>
>
> --
> Best Regards
> Fengli Zhang
>
--
[ signature omitted ]
Message 4 in thread
On Friday 08 June 2007 13:27, ååä wrote:
> Hi,
> I want to read a file into two textEdit at the same time. Firstly, I use
> QTextStream::readAll(), but you konw, the second textEdit couldn't read in
> any word. I think this is because after the first textEdit read all, the
> cursor of the file locate at the end of the file.
> Then, I try QTextStream::readLine() and it works. Both the textEdit could
> read in the file. But the reading speed is very slow. So this method isn't
> approprite also.
> Does anyone have a better idea about this?
> Attached related codes:
> Firstly, I did it this way:
> QFile file(fileName);
> if(file.open(QFile::ReadOnly))
> {
> QTextStream in(&file);
> firstTextEdit->setPlainText(in.readAll);
> secondTextEdit->setPlainText(in.readAll);
> file.close();
> }
> Then I change it to this:
> QFile file(fileName);
> if(file.open(QFile::ReadOnly))
> {
> QTextStream in(&file);
> firstTextEdit->setPlainText(in.readAll);
> secondTextEdit->setPlainText(in.readAll);
> file.close();
> }
Use a QString variable to store the text after you read it from the text
stream:
QTextStream in(&file);
QString text = in.readAll();
firstTextEdit->setPlainText(text);
secondTextEdit->setPlainText(text);
Matthias
--
[ signature omitted ]