Best practice for workaround moc's inability to handle ifdef?



  • I have the following code:

    public slots:
    #if !defined(Q_OS_MACOS)
        void installOrRestartClicked(QAbstractButton* button, QString filePath);
    #endif
    
    #if !defined(Q_OS_MACOS)
    void Updater::installOrRestartClicked(QAbstractButton* button, QString filePath)
    {
    ...
    

    moc on macOS still finds this code and fails the compilation for me:

    /Users/travis/build/Mudlet/Mudlet/build/src/moc_updater.cpp:84:21: error: no member named 'installOrRestartClicked' in 'Updater'
    
            case 1: _t->installOrRestartClicked((*reinterpret_cast< QAbstractButton*(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break;
    
                    ~~  ^
    
    1 error generated.
    

    very annoying. One way to deal with this is to leave the declaration intact and just do:

    void Updater::installOrRestartClicked(QAbstractButton* button, QString filePath)
    {
    #if !defined(Q_OS_MACOS)
    ...
    

    How do other people workaround this moc bug?


  • Lifetime Qt Champion

    Hi,

    What version of Qt are you using ?



  • The latest, 5.9


  • Lifetime Qt Champion

    Can you try with ifndef ?



  • Hi, just guessing, but to add to @SGaist, you could also try to insert an extra #include <QtCore/qglobal.h> somewhere at the top of update.h to make sure that moc really sees the that #define Q_OS_MACOS


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.