[Development] WId type changed on Windows
Jonathan Liu
net147 at gmail.com
Wed Aug 14 15:54:39 CEST 2013
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());
>
> Is this on purpose, or a side effect of the QPA refactoring and the above-mentionned commits?
>
> I'm wondering because the commit log in b03cabc4cdcc says that the purpose of the
> change is exactly that: to be able to cast to HWND. But it was only tested on a 64 bit platform it seems?
Casting should work. See above.
>
> Why don't we simply use HWND on Windows again, like in Qt4, and use
> whatever is needed on Unix (long? quintptr?) ?
>
Regards,
Jonathan
More information about the Development
mailing list