⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)

MOC and Q_OS_XXX defines

  • Hi!
    i am tyring to create a few alternative classes for different platforms and it seems that the moc compiler does not understand any Q_OS_XXX defines. For example the code:

    class Device: public QObject
    ... blah ...
    public slots:
    #ifdef Q_OS_ANDROID
           void mySlot()
    #end if

    The mySlot() is not recognized at runtime and connect that slot result in a runtime error...

    How should i create a platform-dependent slot?

  • Create a parent class with the common code and a platform
    dependent child class for each platform or just don't use
    the platform depended slots in platforms that don't support them.

  • Yes this was already the case.
    I was just trying to avoid compilation of the child class on the wrong platform...

    I solved it by moving the SOURCES and INCLUDES in the "pro" file from the global section to a per-platform specific.


     SOURCES = android-only-class.cpp
     INCLUDES = android-only.headers.h


    unix:android {
     SOURCES += android-only-class.cpp
     INCLUDES += android-only.headers.h

    By the way, the "unix:android" seems to be undocumented, but it works.

Log in to reply