Connect two forms to edit data
-
Hi all,
I have form having
tabwidget
to save data as xml file.I'm looking forward to implement option to
modify
data.I have a button
modify
, when clicked user get a dialogue box to open data. Once an entry selected I can get contents.Now I need to pass these contents to the same
tabwidget
for user to edit. Can you suggest me best way to do this?Thanks in advance
-
@VRonin sorry about my vague explanation. I mean there is
QTabWidget
having many fields to (lineedit
,dateTimeEdit
,textEdit
etc., find screenshot attached) to gather data. ) to collect data -
@russjohn834
So assuming you mean you populate those widgets with what you read from the XML, you will allow the user to edit the content of those widgets and then regenerate the complete new XML (either from scratch, or by modifying the in-memoryQDomDocument
if you are using that) to save back to file. I don't see any (need for) "Connect two forms to edit data".... -
@JonB Thank you. My doubt do I need two identical forms to
save
andmodify
?
At present im presenting user following form for new entry, modify or remove.
When
modify
clicked, user get a dialogue box to open already existing entries. Then the user will be presented with the same tabwidget based form with default values from the read entry. -
@russjohn834
Well, there is no one "right" answer to this. Personally I have found over the years that I don't want to duplicate code or maintain too many forms, so I tend to do it all on one page. I don't know what others might suggest, but:-
Page has form showing record details. Optionally some kind of "navigation", to choose what to read in. May be "master/detail", e.g. (filterable) list/table at top/side to choose which record to read in, clicking record populates form at bottom, or something like that. If you require navigation.
-
Buttons at bottom for actions.
-
For existing record, Update (after edits) and Delete. Optionally, an Edit button to go into edit mode, if you prefer not to allow user to edit automatically.
-
Button New clears out all fields, populating with any defaults for a new record. After this, an Add button does the add of newly typed in stuff.
-
Optionally, Copy on existing record, which effectively does a New followed by copying whatever from existing record to new record, leaving user to edit/press Add.
-
Optionally, Cancel, reverts any pending edits if user does not want to Update/Add.
-
No separate dialog to add/update/delete records. Hence no "Connect two forms to edit data".
But it's up to you!
I will just add that Qt has a nice https://doc.qt.io/qt-5/qdatawidgetmapper.html to map a data model to widgets, to save you the effort. However, this does require a
QAbstractItemModel
derivation, and I'm not sure you want to go down that route for where you are with your XML file. (Possibly see https://doc.qt.io/qt-5/qtwidgets-itemviews-simpledommodel-example.html, but I'm still thinking this will be too hard/unsuitable for you.) -