June 2, 2011

bjvail bjvail
Lab Rat
4 posts

Parsing Text from File

 

I have a text file I am trying to read from. It is delimited by several different characters. Below is a sample of one of the text files I am trying to read:

#1800
@001 State the name of the principal (person giving power):
~Enter the name of the person who is giving the power of
~attorney
@440 Enter the place of residence of the principal:
~Enter the city, state of residence of the person giving the
~power
@441 State the name of the attorney:
~Enter the name of the person to act on your behalf; although
~they are referred to as “Attorney” they do not need to be an
~“Attorney”
@442 Enter the place of residence of the attorney:
~Enter the city, state of the attorney; for example, Buffalo,
~New York
#1801 Will the attorney have BANKING authority?
~Select yes if the attorney will be able to handle banking
~affairs
#if#1801
@443 Name the bank (do not use word bank if it is last):
~Enter the name of the bank; the word bank is supplied in the
~text of the document; for example if the bank is the 4th
~National Bank, simple enter 4th National
@444 Enter the city and state where the bank is located:
~Enter the city, state where the bank is located; for example
~Raleigh, North Carolina
#endif
#1802 Will the attorney execute a deed or real estate conveyance?
~Select yes if the attorney will sign a deed or other real estate
~related document
#if#1802
@445 State the description of the property:
~Enter the legal description of the property; that is the lot and
~block number or a metes and bounds description, NOT the address
#endif
#1803 Will the attorney obtain/review educational records?
~Select yes if the attorney will be able to review or obtain
~educational records
#if#1803
@300 Enter the name of the school or college:
~State the name of the school or college where the attorney will
~be able to review or obtain your records
@301 Enter the city and state where the school is located:
~State the city, state where the school is, for example, Bismark,
~North Dakota
#endif
#1806 Will the attorney have other authority?
~If other powers are to be granted, select yes
#if#1806
@448 State the authority NARROWLY and PRECISELY:
#endif
#1807
@449 Enter the beginning date of the power of attorney:
~State the date when the power of attorney becomes effective
@450 Enter the ending date of the power of attorney:
~State the ending date of the power
@003 Enter the state where signed:
~Enter the name of the state where this document is signed
@004 Enter the county where signed:
~Enter the county, parish, judicial district or borough where
~this power is signed
#end control section
#1800

I want to be able to assign the values without a tilde next to them to a label and the values with a tilde to a text box.

If this is too much to ask for in a forum I will remove the post. I have been racking my brain for a couple weeks on this and feel I have probably overlooked more simpler solutions.

Any and all help will be greatly appreciated.

7 replies

June 2, 2011

Eddy Eddy
Area 51 Engineer
1607 posts

You could read line by line and do whatever you want with it.

What do you have so far?

Do you want to iterate over the lines or do you want to fill a form with several labels and textedits?
Do you need the lines with # in it or only the @ and ~ lines?

 Signature 

Moderator
Qt Certified Specialist
Nokia Qt Ambassador

June 2, 2011

bjvail bjvail
Lab Rat
4 posts

The very first and last # sings can be ignored, they just set up the control file. I would like to fill a form with several labels and textedits, or if it would easier, depending on what character the iterator comes across, call a dialog. I don’t really have any code to show as I was originally attempting this in C#. Woke up one morning and decided it was time to learn C++.

I may be asking too much, but if I could get help with finding a good starting point I could make it roll.

Thanks

June 2, 2011

Eddy Eddy
Area 51 Engineer
1607 posts

In that case i would advise you to read a good starting book like this one :
bq. C++ GUI Programming with Qt 4, by Jasmin Blanchette; Mark Summerfield

If you google you can find a free pdf of it.

Chapter 12. Input/Output explains how you can read your file.
chapter 1,2 gives you a good intro in the use of labels, forms and so on.

If you have specific questions feel free to ask here.

Have fun programming!

 Signature 

Moderator
Qt Certified Specialist
Nokia Qt Ambassador

June 2, 2011

bjvail bjvail
Lab Rat
4 posts

Thanks for help thus far. I recently purchased that book and haven’t made it that far in yet. Guess I should practice patience while simultaneously learning Qt and C++.

Thanks again

June 2, 2011

Eddy Eddy
Area 51 Engineer
1607 posts

Chapters 1 and 2 are easy to start. That way you can already setup the user interface and code the text parsing afterwards.

Your wishes aren’t that complicated and should be rather easy to implement once you know exactly what you want.

 Signature 

Moderator
Qt Certified Specialist
Nokia Qt Ambassador

June 4, 2011

Volker Volker
Ant Farmer
5428 posts

You should have a look into class QTextStream [doc.qt.nokia.com], especially readLine() method.

Then have a look at QString’s [doc.qt.nokia.com] API docs, it has several methods to look into the line you’ve just read. Method startsWith() should be of special interest for you.

June 4, 2011

bjvail bjvail
Lab Rat
4 posts

I appreciate the reply. I don’t think that what I am trying to do is too overly complicated, just seemed like a good project to dive head first into Qt and C++ with. I’ll give it a look.

Thanks again

 
  ‹‹ QPainter::begin: Paint device returned engine == 0, type: 1      Shortcut of Qt application.exe ››

You must log in to post a reply. Not a member yet? Register here!