Qt5.0-beta1 QObject::connect return type and suggested framework operator



  • Hi Guys,
    I'm pretty amazed how easy our migration to Qt5 was, but there was one change that I've needed to do and I think it could be taken into framework itself.

    Compiler: gcc version 4.6.1 (Ubuntu/Linaro 4.6.1-9ubuntu3)

    This lines of codes shows the case:
    @ bool res = true;
    res &= connect( this, SIGNAL(x()), this, SIGNAL(x2()));@

    Qt4.8 passed this cause connect returned bool.
    Qt5.0 returns QMetaObject::Connection and in this case we have compilation error caused by trying to do bitwise or on bool and QMetaObject::Connection.

    To avoid changing code I've defined at global space this operator:
    @bool& operator&=(bool& a_res, const QMetaObject::Connection& a_res2)
    {
    a_res = (a_res & static_cast<bool>(a_res2));
    return a_res;
    }@

    I hope it will help somebody or even get into Qt5.0

    ==
    P4C



  • As the documentation says ("QMetaObject":http://doc-snapshot.qt-project.org/qt5-stable/qtcore/qmetaobject-connection.html ), the & should still work because the Connection defines operator bool()



  • Try it ;-)

    operator&
    is not a operator&=

    "September 18, 2012" ;-D


Log in to reply
 

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