Qbs and Q_PRIVATE_SLOT: doing it right



  • PIMPL is a pattern widely used across the Qt itself and countless Qt-based libraries. Despite the fact that Q_PRIVATE_SLOT macro is currently an undocumented private API, many developers (including me) is using it in their code.

    When compiling the moc-generated file for the header using Q_PRIVATE_SLOT macro we have basically two different ways:

    Somehow include private header to the moc file so the private slot declarations be available at the compile time. It is easily done using -f command line argument when calling moc.

    Do not compile moc file separately and manually include it to your C++ file doing something like #include "moc_yourgloriouspimplclass.cpp" to your class implementation.

    Since I've been using CMake for most of my projects before I generally preferred the first way simply adding something like @QT4_WRAP_CPP(sources include/SomeClass.h
    OPTIONS -f${CMAKE_CURRENT_SOURCE_DIR}/src/SomeClass_p.h)@

    to CMakeLists.txt.

    Currently I'm trying to use qbs and got a general question: what is the right way to build Q_PRIVATE_SLOT-containing classes using qbs? Do I need to find a way to skip MOC-generated file compilation and include it manually or maybe there's a simplier way?

    Thank you in advance.


Log in to reply
 

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