[Interest] Q_OS_ANDROID macro

Constantin Makshin cmakshin at gmail.com
Wed Feb 4 21:15:20 CET 2015


A bit ugly but simple solution is to remove that #ifndef from the header
file and put it to slot method definitions, i.e.:

// header file
public slots:
    void recordAdded(const BonjourRecord &record);
    void recordRemoved(const BonjourRecord &record);
    void bonjourRecordResolved(const QHostInfo &hostInfo, int port);

// .cpp file
void LKBridgeBrowser::recordAdded(const BonjourRecord &record)
{
#if defined(Q_OS_ANDROID)
    Q_UNUSED(record);
#else
    ...
#endif
}

(and the same thing for other slots)

This method should solve the problem with minimal impact on size of the
executable file. As I said, it's a bit ugly because you'll get some
(little) amount of wasted space, but everything should work.
On Feb 4, 2015 9:53 PM, "Nuno Santos" <nunosantos at imaginando.pt> wrote:

>  Hi,
>
> I have found a workaround for the problem. I have included the
> BonjourRecord  header because it doesn't have any dependency on dns_sd.h.
> This way I can safely declare the slots on the header. The main problem
> here is that the moc_ doesn't know about Q_OS_ANDROID when it is generated
> which will generate entry for the slots that shouldn't be there.
>
> public slots:
>     #ifndef Q_OS_ANDROID
>     void recordAdded(const BonjourRecord &record);
>     void recordRemoved(const BonjourRecord &record);
>     void bonjourRecordResolved(const QHostInfo &hostInfo, int port);
>     #endif
>
> Anyway, as you requested, this is the complete output of the error:
>
> .build\moc\moc_LKBridgeBrowser.cpp
> .build\moc\moc_LKBridgeBrowser.cpp: In static member function 'static void
> LKBridgeBrowser::qt_static_metacall(QObject*, QMetaObject::Call, int,
> void**)':
> .build\moc\moc_LKBridgeBrowser.cpp:126:21: error: 'class LKBridgeBrowser'
> has no member named 'recordAdded'
>          case 6: _t->recordAdded((*reinterpret_cast< const
> BonjourRecord(*)>(_a[1]))); break;
>                      ^
> .build\moc\moc_LKBridgeBrowser.cpp:127:21: error: 'class LKBridgeBrowser'
> has no member named 'recordRemoved'
>          case 7: _t->recordRemoved((*reinterpret_cast< const
> BonjourRecord(*)>(_a[1]))); break;
>                      ^
> .build\moc\moc_LKBridgeBrowser.cpp:128:21: error: 'class LKBridgeBrowser'
> has no member named 'bonjourRecordResolved'
>          case 8: _t->bonjourRecordResolved((*reinterpret_cast< const
> QHostInfo(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break;
>                      ^
> In file included from
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qnamespace.h:37:0,
>                  from
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qobjectdefs.h:41,
>                  from
> ..\..\Qt\5.4\5.4\android_armv7\include\QtCore/qobject.h:40,
>                  from
> ..\..\Qt\5.4\5.4\android_armv7\include\QtCore/QObject:1,
>                  from
> .build\moc\../../../../Users/nsantos/Dropbox/workspace/livkontrol/qt/livkontrol/LKBridgeBrowser.h:4,
>                  from .build\moc\moc_LKBridgeBrowser.cpp:9:
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qmetatype.h: In
> instantiation of 'constexpr int qMetaTypeId() [with T = BonjourRecord]':
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qmetatype.h:1655:27:
> required from 'constexpr int qRegisterMetaType() [with T = BonjourRecord]'
> .build\moc\moc_LKBridgeBrowser.cpp:138:85:   required from here
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qglobal.h:684:47: error:
> static assertion failed: Type is not registered, please use the
> Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system
>  #define Q_STATIC_ASSERT_X(Condition, Message)
> static_assert(bool(Condition), Message)
>                                                ^
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qmetatype.h:1648:5: note: in
> expansion of macro 'Q_STATIC_ASSERT_X'
>      Q_STATIC_ASSERT_X(QMetaTypeId2<T>::Defined, "Type is not registered,
> please use the Q_DECLARE_METATYPE macro to make it known to Qt's
> meta-object system");
>      ^
> In file included from
> ..\..\Qt\5.4\5.4\android_armv7\include\QtCore/qobject.h:48:0,
>                  from
> ..\..\Qt\5.4\5.4\android_armv7\include\QtCore/QObject:1,
>                  from
> .build\moc\../../../../Users/nsantos/Dropbox/workspace/livkontrol/qt/livkontrol/LKBridgeBrowser.h:4,
>                  from .build\moc\moc_LKBridgeBrowser.cpp:9:
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qmetatype.h: In
> instantiation of 'static constexpr int QMetaTypeId2<T>::qt_metatype_id()
> [with T = BonjourRecord]':
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qmetatype.h:1649:44:
> required from 'constexpr int qMetaTypeId() [with T = BonjourRecord]'
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qmetatype.h:1655:27:
> required from 'constexpr int qRegisterMetaType() [with T = BonjourRecord]'
> .build\moc\moc_LKBridgeBrowser.cpp:138:85:   required from here
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qmetatype.h:1509:97: error:
> 'qt_metatype_id' is not a member of 'QMetaTypeId<BonjourRecord>'
>      static inline Q_DECL_CONSTEXPR int qt_metatype_id() { return
> QMetaTypeId<T>::qt_metatype_id(); }
>
> ^
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qmetatype.h:1509:100: error:
> body of constexpr function 'static constexpr int
> QMetaTypeId2<T>::qt_metatype_id() [with T = BonjourRecord]' not a
> return-statement
>      static inline Q_DECL_CONSTEXPR int qt_metatype_id() { return
> QMetaTypeId<T>::qt_metatype_id(); }
>
> ^
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qmetatype.h: In static
> member function 'static constexpr int QMetaTypeId2<T>::qt_metatype_id()
> [with T = BonjourRecord]':
> ..\..\Qt\5.4\5.4\android_armv7\include/QtCore/qmetatype.h:1509:100:
> warning: control reaches end of non-void function [-Wreturn-type]
> makefile:37868: recipe for target '.build\obj\moc_LKBridgeBrowser.obj'
> failed
> mingw32-make: *** [.build\obj\moc_LKBridgeBrowser.obj] Error 1
> 18:47:48: The process "C:\Qt\5.4\Tools\mingw491_32\bin\mingw32-make.exe"
> exited with code 2.
> Error while building/deploying project livkontrol (kit: Android for
> armeabi-v7a (GCC 4.9, Qt 5.4.0))
> When executing step "Make"
> 18:47:48: Elapsed time: 00:03.
>
> On 04/02/2015 18:36, Giuseppe D'Angelo wrote:
>
> Il 04/02/2015 11:05, Nuno Santos ha scritto:
>
> When compiling for Android, moc file as complaining about not having the
> implementation of the methods above which means that the preprocessor has
> passed over Q_OS_ANDROID, however, QtCreator had that area greyed out.
>
>
> Could you please send the exact error you're having? I'm interested in
> who's complaining exactly about what.
>
> It shouldn't be moc -- moc can't care less about who implements some
> slots. It could be the compiler (if you're defining member functions
> without declaring them, that is, you're missing the matching #ifndef in
> your .cpp files), or the linker (which would possibly mean that moc picked
> up those member functions and it's referencing them, but their symbols are
> not present in any object file)...
>
> Thanks,
>
>
> _______________________________________________
> Interest mailing listInterest at qt-project.orghttp://lists.qt-project.org/mailman/listinfo/interest
>
>
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20150204/26faa736/attachment.html>


More information about the Interest mailing list