[Development] changing Q_GADGET

Sune Vuorela nospam at vuorela.dk
Sat Nov 29 19:59:14 CET 2014


On 2014-11-28, Simon Hausmann <simon.hausmann at theqtcompany.com> wrote:
> I feel that Q_GADGET has its primary use with structures and the default 
> access level for those is public. I find it awkward that you currently have to 
> write:

I have a lot of code in the wild using classes and Q_GADGET. 

Having Q_GADGET not change stuff at the end is likely ok, if Q_GADGET
doesn't change accesslevel in the beginning.

But doesn't Q_GADGET start with changing accesslevel to public?

The only safe way is to then switch to private.

class MyClass 
{
    Q_GADGET
    class MyPrivate;
    int m_myCounter;
public: 
    MyClass);
}

> The proposed change would have two effects:
>
> 1) It makes any existing code that _relies_ on Q_GADGET turning to private 
> suddenly expose members in structures.
>
> 2) On paper it breaks binary compatibility with MSVC, in the unlikely event 
> that somebody 
>     a) produces a DLL and cares about binary compatibility
>     b) exposes bare structures
>     c) relies on Q_GADGET turning access permission levels to private

3) Making accesslevel public for private class members.

/Sune




More information about the Development mailing list