Important: Please read the Qt Code of Conduct -

MOC don't generate slots that inside #if-#endif directives

  • Hi,

    I'm writing an app that runs on Windows and Android. Some functions are not available on Windows so I encapsulated them between #if..#endif directives.
    @#if defined( Q_OS_ANDROID ) || defined( Q_OS_LINUX )
    // Some code

    Some of my slots are encapsulated between those, and if use the following code to connect those slots, it doesn't work.
    @connect( emitter, SIGNAL(signalToEmit(), receiver, SLOT(slotToConnect() )@

    Qt says that the slot doesn't exist. Which is true, I checked the file generated by MOC and the slots are missing. I know I can use the following code but it doesn't work when there are some overloaded signals or slots.
    @connect( emitter, &EmitterClass::signalToEmit, receiver, &ReceiverClass::slotToConnect )@

    I tried to add DEFINES += Q_OS_ANDROID in the pro file but this generates errors at compilation time.
    So what must I do to make sure MOC will see the code encapsulated between #if .. #endif directives.


Log in to reply