[Qt-interest] Default get/set

Jason H scorp1us at yahoo.com
Thu Jul 28 15:54:33 CEST 2011


I've always coded a solution for this, but I'm wondering if others would want it, and why it hasn't already been done (generally by now, if its not done, its not a good idea)

Anyway, I'd love to have a generic getter/setter on QWidgets that maps to the userProperty().

I know there are a variety of approaches, using QDataWidgetMapper (for matting to model roles) but many times that is overkill. Maybe it's bad design that I name my database fields the same as my widgets, or I'm not using Qt correctly, but I'd love to have a form or result set be able to share data without a lot of coding.

init:

QMap<Qstring, QWidget*> widgetMap;

foreach (QString column, queryResults.columns())
{
    QWidget *w = findWidget(column);
    if (w) widgetMap[column]=w;
}

load:

foreach (QString name, widgetMap.keys())
{
    widgetMap[name].set(queryResults[name]);
}

save:

foreach (QString name, widgetMap.keys())
{
    updateQuery.bindValue(name, widgetMap[name].get());
}

It's just be nice to not have to care about the specific member function unless you really have to. The most complicated example I can come up with is setting a selection list for QListBox.

If a generic get/set is considered bad, what about widget.userProperty().get() and widget.userProperty().set(...)

Thoughts?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110728/68233300/attachment.html 


More information about the Qt-interest-old mailing list