PDA

View Full Version : Easy data pipe from many QLineEdits to QStandardModel and QXMLStreamWriter



homerun4711
21st December 2010, 15:55
Hello!

I am trying to build a low-maintenance-data-pipe from a QDialog's QLineEdits to a QStandardModel or a QXMLStreamWriter.

So far the quick and dirty solution would be to read all QLineEdits into QStrings and put them into the QStandardModelItem or the QXMLStreamWriter.

But this is relative unflexible, because I have to do a lot of rewriting if LineEdits are added or removed.

I thought of setting up a QStringList with names of all QLineEdits and iterate through them to fetch the values. But this still needs some maintance if the QLineEdits change.

Can someone of you point me to a better solution?
Pieces of code are welcome :)

Kind regards,
HomeR

tbscope
21st December 2010, 16:34
class HandleLineEdits : public SomethingLikeQObject
{
public:
HandleLineEdits();

void addLineEdit(QLineEdit *lineEdit);

void doSomethingUsefullWithTheLineEdits();

private:
QList<QLineEdit *> lineEdits;
};

Change to your own preference and improve the code (errors).

homerun4711
21st December 2010, 20:43
Thank you very much, this looks quite good.
Always think object-oriented :)