Thanks for the input guys. Given what I had to work with, I was able to save a local hash of the context and widget and do a lookup from that. However, It’s nice to know QWidget::find(wID) is well optimized. I wonder what the performance is of the Windows function WindowFromDC? Oh well, I don’t need to worry about it now.
Thanks again. > On Jan 7, 2015, at 6:31 PM, Thiago Macieira <thiago.macie...@intel.com> wrote: > > On Wednesday 07 January 2015 15:16:56 Jason Dolan wrote: >> I’m stuck with some 3rd party code where the input is a device context >> (HDC), and I need to get the widget it’s associated with. >> >> My current implementation (completely untested as of yet) is: >> QWidget *w = QWidget::find((WId)WindowFromDC(hDC)); >> >> #1: I’m not even sure this will work (although I think it will) — I’m coding >> under OS X right now and will have to test on our windows build machine in >> a bit >> #2: This needs to be as fast as possible as this can be called ALOT. >> Any time the function says “find” I get worried about speed… > > It's pretty quick: > > QWidget *QWidget::find(WId id) > { > return QWidgetPrivate::mapper ? QWidgetPrivate::mapper->value(id, 0) : 0; > } > > And QWidgetPrivate::mapper is a QHash<WId, QWidget *>, so this should be O(1) > for the general case. > > -- > Thiago Macieira - thiago.macieira (AT) intel.com > Software Architect - Intel Open Source Technology Center > > _______________________________________________ > Interest mailing list > Interest@qt-project.org > http://lists.qt-project.org/mailman/listinfo/interest Jason Dolan Software Developer Physician's Computer Company 20 Winooski Way, Suite #7, Winooski, VT 05404
_______________________________________________ Interest mailing list Interest@qt-project.org http://lists.qt-project.org/mailman/listinfo/interest