Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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
    {    
         Q_OBJECT
    ... 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.

    Before:

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

    After:

    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