FAQ
I have quite a bit of code that needs to be disabled when building for
Android (mostly the sound output routines). So I'm doing stuff like:

#ifndef ANDROID
// Sound-related code here
#else
// no-op on Android
#endif

However, moc doesn't seem to respect the ANDROID (or Q_OS_ANDROID)
macro. For example:

#ifndef ANDROID
signals:
void musicVolChange();
#endif

Results in a build error like:

tmp/moc_qtadssound.cpp:58: error: 'class MusicPart' has no
member named 'musicVolChange'

What can I do here? As mentioned above, I also tried Q_OS_ANDROID, but
that won't work either. Note that the compiler sees that macro. It's
just moc that doesn't.

Search Discussions

  • Konrad Rosenbaum at Sep 24, 2012 at 9:04 am

    On Sunday 23 September 2012 17:50:03 Nikos Chantziaras wrote:
    I have quite a bit of code that needs to be disabled when building for
    Android (mostly the sound output routines). So I'm doing stuff like:

    #ifndef ANDROID
    // Sound-related code here
    #else
    // no-op on Android
    #endif

    However, moc doesn't seem to respect the ANDROID (or Q_OS_ANDROID)
    macro.
    Moc has very limited recognition of pre-processor symbols. You have found one
    of the limits. There is no simple workaround for this.
    For example:

    #ifndef ANDROID
    signals:
    void musicVolChange();
    #endif

    Results in a build error like:

    tmp/moc_qtadssound.cpp:58: error: 'class MusicPart' has no
    member named 'musicVolChange'

    What can I do here? As mentioned above, I also tried Q_OS_ANDROID, but
    that won't work either. Note that the compiler sees that macro. It's
    just moc that doesn't.
    There is no need to disable signals like this. You simply do not call the
    signal, its existence is a very small overhead that can be ignored in light of
    the size of Qt.

    Likewise with slots you have to disable their function body, but not their
    declaration:

    void MyClass::mySlot()
    {
    #ifdef ANDROID
    qWarning("mySlot called in Android environment! Help! Help!");
    #else
    //real code
    #endif
    }

    If other places rely on those signals and/or slots, you should provide either
    macros:

    #ifdef ANDROID
    #define HAVE_MYFEATURE 0
    #else
    #define HAVE_MYFEATURE 1
    #endif

    and/or query-methods:
    class MyClass: ... {
    public:
    bool hasMyFeature()const{
    #ifdef ANDROID
    return false;
    #else
    return true;
    }
    };

    The reason for this is: the rules in which environment the feature is
    available may change (Android may gain the feature, you may port to platforms
    that do not have it either).



    Konrad

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupandroid-qt @
categoriesandroid
postedSep 23, '12 at 3:50p
activeSep 24, '12 at 9:04a
posts2
users2
websiteandroid.com

People

Translate

site design / logo © 2021 Grokbase