Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
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:
@001 State the name of the principal (person giving power):
~Enter the name of the person who is giving the power of
@440 Enter the place of residence of the principal:
~Enter the city, state of residence of the person giving the
@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
@442 Enter the place of residence of the attorney:
~Enter the city, state of the attorney; for example, Buffalo,
#1801 Will the attorney have BANKING authority?
~Select yes if the attorney will be able to handle banking
@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
#1802 Will the attorney execute a deed or real estate conveyance?
~Select yes if the attorney will sign a deed or other real estate
@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
#1803 Will the attorney obtain/review educational records?
~Select yes if the attorney will be able to review or obtain
@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,
#1806 Will the attorney have other authority?
~If other powers are to be granted, select yes
@448 State the authority NARROWLY and PRECISELY:
@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
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.
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?
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.
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!
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++.
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.
goetz last edited by
You should have a look into class "QTextStream":http://doc.qt.nokia.com/4.7/qtextstream.html, especially readLine() method.
Then have a look at "QString's":http://doc.qt.nokia.com/4.7/qstring.html API docs, it has several methods to look into the line you've just read. Method startsWith() should be of special interest for you.
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.