[Development] WId type changed on Windows

David Faure david.faure at kdab.com
Wed Aug 14 16:13:14 CEST 2013


On Wednesday 14 August 2013 23:54:39 Jonathan Liu wrote:
> On 14/08/2013 11:33 PM, David Faure wrote:
> > The combination of b03cabc4cdcc and 66febd27cb in qtbase, broke source
> > compatibility on Windows 32 bit (MSVC).
> > 
> > We now have
> > 
> >     typedef QT_PREPEND_NAMESPACE(quintptr) WId;
> > 
> > while in Qt4, it was
> > 
> >    typedef HWND WId.
> > 
> > This breaks compilation of source code like:
> >     QMenu *menu = new QMenu(0);
> >     HWND hWnd = menu->winId(); // error on this line
> >     SetClassLong(hWnd, GCL_STYLE, GetClassLong(hWnd, GCL_STYLE) &
> >     (~CS_DROPSHADOW));> 
> > Because WId cannot be casted to a HWND
> > 
> >   (on Windows XP 32 bits, with MSVC 2010).
> 
> You mean implicit conversion from integral type to pointer type? A cast
> is explicit. WId is an integral type while HWND is a pointer type.
> Before b03cabc4cdcc, WId was a typedef of unsigned long which is still
> an integral type and would still have the same issue.
> 
> The following casts should work:
> HWND hWnd = (HWND)(menu->winId());
> HWND hWnd = reinterpret_cast<HWND>(menu->winId());
> HWND hWnd = HWND(menu->winId());

Yes of course. Sorry, I meant implicit conversion.
Explicit casting wasn't necessary with the Qt4 typedef.

I see, your commit log for b03cabc4cdcc was about making explicit casting even 
feasible in the first place, by using a big enough data type on win64.
That's even more important of course ;)

But I'm still wondering if we couldn't fix this source incompatibility with 
Qt4. Or in other words, if we could fix the need for this ugly casting, even 
leaving qt4 aside.

-- 
David Faure | david.faure at kdab.com | Managing Director KDAB France
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions




More information about the Development mailing list