Qt-interest Archive, December 2006
About QFile and QTextStream
Message 1 in thread
My code is like this:
...
QTextStream inTextStream(&inFile);
line = inTextStream.readLine();
filePOS = inFile.pos();
...
If i read a line use QTextStream, can i get the updated file postion using
associated QFile?
If not, is there any smart way to do this?
Thanks!
Message 2 in thread
On 11.12.06 22:53:31, cookiecc chu wrote:
> My code is like this:
> ...
> QTextStream inTextStream(&inFile);
> line = inTextStream.readLine();
> filePOS = inFile.pos();
> ...
>
> If i read a line use QTextStream, can i get the updated file postion using
> associated QFile?
Did you try your example?
> If not, is there any smart way to do this?
I'd probably use QTextStream::pos()
Andreas
--
[ signature omitted ]
Message 3 in thread
But there is no QTextStream::pos() exist There is only seek() >_<
currently, i have to count the characters i have read to get the postion in
the text file
I though maybe the QTextStream deals with just the character data, which
makes getting
the postion of file much easier.
2006/12/11, Andreas Pakulat <apaku@xxxxxx>:
>
> On 11.12.06 22:53:31, cookiecc chu wrote:
> > My code is like this:
> > ...
> > QTextStream inTextStream(&inFile);
> > line = inTextStream.readLine();
> > filePOS = inFile.pos();
> > ...
> >
> > If i read a line use QTextStream, can i get the updated file postion
> using
> > associated QFile?
>
> Did you try your example?
>
> > If not, is there any smart way to do this?
>
> I'd probably use QTextStream::pos()
>
> Andreas
>
> --
> You'll feel devilish tonight. Toss dynamite caps under a flamenco
> dancer's
> heel.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Message 4 in thread
On 11.12.06 23:22:56, cookiecc chu wrote:
> But there is no QTextStream::pos() exist There is only seek() >_<
Then next time, better tell us you're using Qt3 ;)
> currently, i have to count the characters i have read to get the postion in
> the text file
> I though maybe the QTextStream deals with just the character data, which
> makes getting
> the postion of file much easier.
In Qt3 the QFile function for finding the position is called at() and
works here perfectly:
Andreas
--
[ signature omitted ]
Message 5 in thread
I am using Qt4.14 free version, not Qt3
there is no QTextStream::pos() indeed
ORZ
2006/12/11, Andreas Pakulat <apaku@xxxxxx>:
>
> On 11.12.06 23:22:56, cookiecc chu wrote:
> > But there is no QTextStream::pos() exist There is only seek() >_<
>
> Then next time, better tell us you're using Qt3 ;)
>
> > currently, i have to count the characters i have read to get the postion
> in
> > the text file
> > I though maybe the QTextStream deals with just the character data, which
> > makes getting
> > the postion of file much easier.
>
> In Qt3 the QFile function for finding the position is called at() and
> works here perfectly:
>
> Andreas
>
> --
> Write yourself a threatening letter and pen a defiant reply.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Message 6 in thread
On 12/12/06, cookiecc chu <cookiecc@xxxxxxxxx> wrote:
> I am using Qt4.14 free version, not Qt3
> there is no QTextStream::pos() indeed
pos() seems to added in 4.2, maybe it's time to upgrade :)
Oh, and it's 4.1.4, not 4.14
--
[ signature omitted ]
Message 7 in thread
On 12.12.06 09:23:25, cookiecc chu wrote:
> I am using Qt4.14 free version, not Qt3
> there is no QTextStream::pos() indeed
Then use QFile::pos(), that works. (As Robin said, QTextStream::pos()
was added with 4.2).
The only occassion where you don't get the file position is if you did
not open the file before creating the stream on it.
Andreas
--
[ signature omitted ]
Message 8 in thread
OK, maybe i should update to 4.2 :)
Because the data i deal with is just text, so i can count the characters to
do the pos()
and the QTextStream's readLine() is more comfortable to use (i think :))
I have solved this problem.
Thanks for your help, thanks indeed, my friend!
2006/12/12, Andreas Pakulat <apaku@xxxxxx>:
>
> On 12.12.06 09:23:25, cookiecc chu wrote:
> > I am using Qt4.14 free version, not Qt3
> > there is no QTextStream::pos() indeed
>
> Then use QFile::pos(), that works. (As Robin said, QTextStream::pos()
> was added with 4.2).
>
> The only occassion where you don't get the file position is if you did
> not open the file before creating the stream on it.
>
> Andreas
>
> --
> You have a strong desire for a home and your family interests come first.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Message 9 in thread
On 12.12.06 23:12:15, cookiecc chu wrote:
> OK, maybe i should update to 4.2 :)
> Because the data i deal with is just text, so i can count the characters to
> do the pos()
> and the QTextStream's readLine() is more comfortable to use (i think :))
Maybe I wasn't clear, but QFile::pos() works even when reading with
QTextStream (and its readLine method). So no need to update (although
I'd suggest it) and no need to use sth inconvienent.
Andreas
--
[ signature omitted ]
Message 10 in thread
I write a simple program to make a test:
========================================
#include <QTextStream>
#include <QFile>
#include <QString>
using namespace std;
int main(int argc, char **argv)
{
QString inputFileName = "in.txt";
QString outputFileName = "out.txt";
QFile inFile(inputFileName); // create file object
QFile outFile(outputFileName);
if (!inFile.open(QFile::ReadOnly | QFile::Text)) {
return 1;
}
QTextStream inTextStream(&inFile);
if (!outFile.open(QFile::WriteOnly | QFile::Text)) {
return 1;
}
QTextStream outTextStream(&outFile);
qint64 fileStart = inFile.pos();
outTextStream << fileStart << endl;
QString line;
qint64 filePOS;
for (int i=0; i<10; i++) {
line = inTextStream.readLine();
filePOS = inFile.pos();
outTextStream << filePOS << endl;
}
inFile.close();
outFile.close();
return 0;
}
========================================
The in.txt just contain some text(whatever the content is), and after
running the program,
in the out.txt, i just got as following:
0
16384
16384
16384
16384
16384
16384
16384
16384
16384
16384
It seems that the QFile::pos() can not work properly, so i guess the
QFile::pos() can not work with QTextStream::readLine()
2006/12/13, Andreas Pakulat <apaku@xxxxxx>:
>
> On 12.12.06 23:12:15, cookiecc chu wrote:
> > OK, maybe i should update to 4.2 :)
> > Because the data i deal with is just text, so i can count the characters
> to
> > do the pos()
> > and the QTextStream's readLine() is more comfortable to use (i think :))
>
> Maybe I wasn't clear, but QFile::pos() works even when reading with
> QTextStream (and its readLine method). So no need to update (although
> I'd suggest it) and no need to use sth inconvienent.
>
> Andreas
>
> --
> So this is it. We're going to die.
>
> --
> To unsubscribe - send a mail to qt-interest-request@xxxxxxxxxxxxx with
> "unsubscribe" in the subject or the body.
> List archive and information: http://lists.trolltech.com/qt-interest/
>
>
Message 11 in thread
On 13.12.06 12:42:08, cookiecc chu wrote:
> 0
> 16384
> 16384
> 16384
> 16384
> 16384
> 16384
> 16384
> 16384
> 16384
> 16384
>
> It seems that the QFile::pos() can not work properly, so i guess the
> QFile::pos() can not work with QTextStream::readLine()
Weird, it works in PyQt4, it doesn't work in C++ Qt4.2 with QFile::pos.
So I guess you have to update (which is a good idea anyways)
Andreas
--
[ signature omitted ]
Message 12 in thread
Andreas Pakulat wrote:
> On 13.12.06 12:42:08, cookiecc chu wrote:
>> 0
>> 16384
>> 16384
>> 16384
>> 16384
>> 16384
>> 16384
>> 16384
>> 16384
>> 16384
>> 16384
>>
>> It seems that the QFile::pos() can not work properly, so i guess the
>> QFile::pos() can not work with QTextStream::readLine()
>
> Weird, it works in PyQt4, it doesn't work in C++ Qt4.2 with QFile::pos.
> So I guess you have to update (which is a good idea anyways)
>
> Andreas
>
If I was a QTextStream I would eat as much as I can get from the input
device as well (in a sensible range, though:)
I guess, this is what happens here. If it does work in PyQt4, may be the
file/textstream combination works in an unbuffered way (which would make
sense, when the file does buffering by itself)?
Anyhow: I would not rely on QFile::pos() working when the pos() I need
is actually QTextStream's. Im glad, the trolls added QTextStream::pos.
/eno
--
[ signature omitted ]
Message 13 in thread
On 13.12.06 13:00:59, Enrico Thierbach wrote:
> If it does work in PyQt4, may be the file/textstream combination works
> in an unbuffered way (which would make sense, when the file does
> buffering by itself)?
Well, PyQt4 doesn't change the way QFile and QTextStream work, its just
a wrapper around the C++ classes to use them in Python. And I did use
QFile and QTextStream, I'll do another check later today...
Andreas
> Anyhow: I would not rely on QFile::pos() working when the pos() I need is actually QTextStream's.
> Im glad, the trolls added QTextStream::pos.
Yes, especially as the QTextStream position might be different from the
file-position in multi-byte textfiles.
Andreas
--
[ signature omitted ]
Message 14 in thread
On 12/11/06, cookiecc chu <cookiecc@xxxxxxxxx> wrote:
> My code is like this:
> ...
> QTextStream inTextStream(&inFile);
> line = inTextStream.readLine();
> filePOS = inFile.pos();
There is a readLine in QFile (from QIODevice) as well.
--
[ signature omitted ]