| Trolltech Home | Qt-interest Home | Recent Threads | All Threads | Author | Date | |
| All threads index page 3 | |
I need a help regarding file operation QTextStream stream( &myFile ); // Set the stream to read from myFile line = stream.readLine(); After reading line by line for some time I wanted to ignore some of the upcoming lines and go to some line directly and read, Let say if I want to go the 4 line down and read that is there any way to go to a particular line directly without calling stream.readLine again and again to increment index. Regards Manish
Agarwal Manish Kumar-A17122 wrote: > I need a help regarding file operation > QTextStream stream( &myFile ); // Set the stream to read from myFile > line = stream.readLine(); > After reading line by line for some time I wanted to ignore some of the > upcoming lines and go to some line directly and read, > Let say if I want to go the 4 line down and read that is there any way > to go to a particular line directly without calling stream.readLine > again and again to increment index. No. Andreas -- [ signature omitted ]
Nope... Not unless the length of each line is known... Scott ________________________________ From: Agarwal Manish Kumar-A17122 [mailto:manishk.a@xxxxxxxxxxxx] Sent: Thursday, January 18, 2007 11:10 PM To: qt-interest@xxxxxxxxxxxxx Subject: Go to particular line wile reading file I need a help regarding file operation QTextStream stream( &myFile ); // Set the stream to read from myFile line = stream.readLine(); After reading line by line for some time I wanted to ignore some of the upcoming lines and go to some line directly and read, Let say if I want to go the 4 line down and read that is there any way to go to a particular line directly without calling stream.readLine again and again to increment index. Regards Manish
Scott Aron Bloom wrote: > Nope... Not unless the length of each line is known... ...in bytes ;-). -- [ signature omitted ]
Hi Manish What are you trying to do -- and why do you need to miss out certain lines in the file? If you have control over the file you're reading, maybe you should use XML instead of plain text? Sam Dutton SAM DUTTON SENIOR SITE DEVELOPER 200 GRAY'S INN ROAD LONDON WC1X 8XZ UNITED KINGDOM T +44 (0)20 7430 4496 F E SAM.DUTTON@xxxxxxxxx WWW.ITN.CO.UK ________________________________ From: Agarwal Manish Kumar-A17122 [mailto:manishk.a@xxxxxxxxxxxx] Sent: Fri 19/01/2007 07:10 To: qt-interest@xxxxxxxxxxxxx Subject: Go to particular line wile reading file I need a help regarding file operation QTextStream stream( &myFile ); // Set the stream to read from myFile line = stream.readLine(); After reading line by line for some time I wanted to ignore some of the upcoming lines and go to some line directly and read, Let say if I want to go the 4 line down and read that is there any way to go to a particular line directly without calling stream.readLine again and again to increment index. Regards Manish Please Note: Any views or opinions are solely those of the author and do not necessarily represent those of Independent Television News Limited unless specifically stated. This email and any files attached are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error, please notify postmaster@xxxxxxxxx Please note that to ensure regulatory compliance and for the protection of our clients and business, we may monitor and read messages sent to and from our systems. Thank You.
Sam, I am trying to read configuration file which is a txt file, now its in specific format and holds number of items.Item's length may vary, I am also not sure about number of items in the file Item1 item2 item3 item4 item5... I need to skip some items in the file to go to a specific items, let say I wanted to access item 4 directly. right now to go to item 4 I need to call line = stream.readLine() 3 times, Is there any way to avoid this ? Thanks Manish ________________________________ From: Dutton, Sam [mailto:Sam.Dutton@xxxxxxxxx] Sent: Friday, January 19, 2007 4:29 PM To: qt-interest@xxxxxxxxxxxxx Subject: RE: Go to particular line wile reading file Hi Manish What are you trying to do -- and why do you need to miss out certain lines in the file? If you have control over the file you're reading, maybe you should use XML instead of plain text? Sam Dutton Please Note: Any views or opinions are solely those of the author and do not necessarily represent those of Independent Television News Limited unless specifically stated. This email and any files attached are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error, please notify postmaster@xxxxxxxxx Please note that to ensure regulatory compliance and for the protection of our clients and business, we may monitor and read messages sent to and from our systems. Thank You. SAM DUTTON SENIOR SITE DEVELOPER 200 GRAY'S INN ROAD LONDON WC1X 8XZ UNITED KINGDOM T +44 (0)20 7430 4496 F E SAM.DUTTON@xxxxxxxxx WWW.ITN.CO.UK ________________________________ From: Agarwal Manish Kumar-A17122 [mailto:manishk.a@xxxxxxxxxxxx] Sent: Fri 19/01/2007 07:10 To: qt-interest@xxxxxxxxxxxxx Subject: Go to particular line wile reading file I need a help regarding file operation QTextStream stream( &myFile ); // Set the stream to read from myFile line = stream.readLine(); After reading line by line for some time I wanted to ignore some of the upcoming lines and go to some line directly and read, Let say if I want to go the 4 line down and read that is there any way to go to a particular line directly without calling stream.readLine again and again to increment index. Regards Manish
Am Freitag, 19. Januar 2007 12:08 schrieb Agarwal Manish Kumar-A17122: > Sam, > > I am trying to read configuration file which is a txt file, now its in > specific format and holds number of items.Item's length may vary, I am > also not sure about number of items in the file > > Item1 > item2 > item3 > item4 > item5... > > I need to skip some items in the file to go to a specific items, let say > I wanted to access item 4 directly. > > right now to go to item 4 I need to call line = stream.readLine() 3 > times, Is there any way to avoid this ? I advise using XML as config-file format which solves all the problems you otherwise have to deal with. toby
Attachment:
Attachment:
pgp0xuQFvJbjo.pgp
Description: PGP signature
Message 8 in thread
Hi Manish,
If XML is to heavy for your needs you can use QSettings instead. When
you are using QSettings::IniFormat then you also are platform independent.
Regards,
Falko
--- Original-Nachricht ---
Absender: Tobias Doerffel
Datum: 19.01.2007 12:12
> Am Freitag, 19. Januar 2007 12:08 schrieb Agarwal Manish Kumar-A17122:
>
> I advise using XML as config-file format which solves all the problems you
> otherwise have to deal with.
>
> toby
>
Message 9 in thread
On 19.01.07 12:12:08, Tobias Doerffel wrote:
> Am Freitag, 19. Januar 2007 12:08 schrieb Agarwal Manish Kumar-A17122:
> > Sam,
> >
> > I am trying to read configuration file which is a txt file, now its in
> > specific format and holds number of items.Item's length may vary, I am
> > also not sure about number of items in the file
> >
> > Item1
> > item2
> > item3
> > item4
> > item5...
> >
> > I need to skip some items in the file to go to a specific items, let say
> > I wanted to access item 4 directly.
> >
> > right now to go to item 4 I need to call line = stream.readLine() 3
> > times, Is there any way to avoid this ?
> I advise using XML as config-file format which solves all the problems you
> otherwise have to deal with.
And I advise to not use XML als configuration file, at least not without
some serious thinking. XML bloats configuration files, makes it
near to impossible to share them in svn or cvs and needs a full blown
XML parser. Simple configuration files like QSettings provide can IMHO
cover most of the configuration needs one has.
Andreas
--
[ signature omitted ]
Message 10 in thread
Do you own the creation of the config file? If so, then as others have
said, you should consider using QSettings for reading and writing.
If you don't own its creation, then your kinda stuck.
Here is what I have done for the exact reason you might be hitting...
Create a QStringList
Read the entire file into the QStringList one line at a time, without
any processing of the file
Then read from the QStringList buffer to analyze, then of course random
access 1 line at time is a trivial exercise.
Scott
________________________________
From: Agarwal Manish Kumar-A17122 [mailto:manishk.a@xxxxxxxxxxxx]
Sent: Friday, January 19, 2007 3:09 AM
To: Dutton, Sam; qt-interest@xxxxxxxxxxxxx
Subject: RE: Go to particular line wile reading file
Sam,
I am trying to read configuration file which is a txt file, now its in
specific format and holds number of items.Item's length may vary, I am
also not sure about number of items in the file
Item1
item2
item3
item4
item5...
I need to skip some items in the file to go to a specific items, let say
I wanted to access item 4 directly.
right now to go to item 4 I need to call line = stream.readLine() 3
times, Is there any way to avoid this ?
Thanks
Manish
________________________________
From: Dutton, Sam [mailto:Sam.Dutton@xxxxxxxxx]
Sent: Friday, January 19, 2007 4:29 PM
To: qt-interest@xxxxxxxxxxxxx
Subject: RE: Go to particular line wile reading file
Hi Manish
What are you trying to do -- and why do you need to miss out certain
lines in the file?
If you have control over the file you're reading, maybe you should use
XML instead of plain text?
Sam Dutton
Please Note:
Any views or opinions are solely those of the author and do not
necessarily represent
those of Independent Television News Limited unless specifically stated.
This email and any files attached are confidential and intended solely
for the use of the individual
or entity to which they are addressed.
If you have received this email in error, please notify
postmaster@xxxxxxxxx
Please note that to ensure regulatory compliance and for the protection
of our clients and business,
we may monitor and read messages sent to and from our systems.
Thank You.
SAM DUTTON
SENIOR SITE DEVELOPER
200 GRAY'S INN ROAD
LONDON
WC1X 8XZ
UNITED KINGDOM
T +44 (0)20 7430 4496
F
E SAM.DUTTON@xxxxxxxxx
WWW.ITN.CO.UK
________________________________
From: Agarwal Manish Kumar-A17122 [mailto:manishk.a@xxxxxxxxxxxx]
Sent: Fri 19/01/2007 07:10
To: qt-interest@xxxxxxxxxxxxx
Subject: Go to particular line wile reading file
I need a help regarding file operation
QTextStream stream( &myFile ); // Set the stream to read from myFile
line = stream.readLine();
After reading line by line for some time I wanted to ignore some of the
upcoming lines and go to some line directly and read,
Let say if I want to go the 4 line down and read that is there any way
to go to a particular line directly without calling stream.readLine
again and again to increment index.
Regards
Manish