[Development] moc 4.8.6 & macros

Samuel Gaist samuel.gaist at edeltech.ch
Tue Sep 16 23:00:06 CEST 2014


On 12 sept. 2014, at 11:14, Olivier Goffart <olivier at woboq.com> wrote:

> On Thursday 11 September 2014 22:03:03 Samuel Gaist wrote:
>> On 11 sept. 2014, at 21:49, Thiago Macieira <thiago.macieira at intel.com> 
> wrote:
>>> On Thursday 11 September 2014 21:44:15 Samuel Gaist wrote:
>>>> What would be the correct procedure to handle QT_DEPRECATED_SINCE ?
>>>> Removing it from around the signal declaration would make the code a bit
>>>> inconsistent.
>>>> 
>>>> By the way, how is it handled in Qt 5 since building goes without any
>>>> problem even with the macros around the signal ?
>>> 
>>> moc is smarter in Qt 5: it expands macros.
>>> 
>>> But the recommendation stands: do not #if (of any kind) anything that
>>> isn't
>>> #defined in the same source, in a header next to the one being compiled,
>>> or
>>> passed as -D in the command-line.
>>> 
>>> That means: don't hide signals and slots with #if, even for deprecation.
>> 
>> I thought I've read somewhere that moc got better at this job :-)
> 
> I would not be as strict as Thiago.  
> In Qt5 it's fine to use the preprocessor as long as moc can see the defines 
> (that is, if they don't rely on compiler built-in or need special include 
> paths.)
> QT_DEPRECATED_SINCE should be fine.
> 
> It is strange it does not work with Qt4.  Are you sure that all the include 
> paths are passed to moc?

Good question, I'll have to check. 
If that where not the case, what should I write to give additional include paths to moc ?

> Otherwise, you will have to work around it somehow.
> try #if not QT_DEPRECATED_SINCE() #else
> Or some other trick with Q_MOC_RUN

I forgot about that one, might be a starting point

> 
> You can also use the QT_MOC_COMPAT macro in front of a declaration so QObject 
> will throw a runtime warning when connecting to this signal. (in debug mode)

Good to know

> 
>> It seems that the new moc doesn't use much of the Qt 5 only classes, would
>> it be useful to backport it to Qt 4 to avoid having to "break" the code
>> style for modules supporting both series ?
> 
> This is out of question.
> This is a behaviour change as Qt4 code relied on moc not expending the macro 
> in some cases.
> 
> (At some point it will be time to switch fully to Qt5 and drop Qt4 support)

I agree, but there are still lots of people locked to Qt 4… There's even posts on the forum asking for Qt 3





More information about the Development mailing list