Important: Please read the Qt Code of Conduct -

Upgrading from qt4 to qt5

  • Recently I tried to recompile my programs (used to work fine with qmake-qt4) with qmake-qt5. I found I have to add a line 'QT+=widgets' in .pro file. Except this, my g++ compiler always issues: error: no match for ‘operator==’ (operand types are ‘QMetaObject::Connection’ and ‘bool’) and a long list of candidates follow for each "if(QObject::connect(...)==false) {/.../}" statement.

    Question1: How to fix this problem
    Question2: Is there any general HOWTO about changes from compiling qt4 programs with qmake-qt5

  • Lifetime Qt Champion


    Please show the connect statements you are using.

    As for the porting guide, see the related chapter in Qt's documentation.

  • q_v4l2.cpp: In constructor ‘MainWidget::MainWidget(const char*, QWidget*, unsigned int, unsigned int)’:
    q_v4l2.cpp:64:53: error: no match for ‘operator==’ (operand types are ‘QMetaObject::Connection’ and ‘bool’)
    if(QObject::connect(m_qtmr, SIGNAL(timeout()),
    this, SLOT(update()) )==false) {
    In file included from /usr/include/qt5/QtCore/qstring.h:48,
    from /usr/include/qt5/QtCore/qobject.h:47,
    from /usr/include/qt5/QtCore/qabstractanimation.h:43,
    from /usr/include/qt5/QtCore/QtCore:5,
    from /usr/include/qt5/QtWidgets/QtWidgetsDepends:3,
    from /usr/include/qt5/QtWidgets/QtWidgets:3,
    from q_v4l2.cpp:22:
    /usr/include/qt5/QtCore/qchar.h:598:30: note: candidate: ‘constexpr bool operator==(QChar, QChar)’
    Q_DECL_CONSTEXPR inline bool operator==(QChar c1, QChar c2) Q_DECL_NOTHROW { return c1.ucs == c2.ucs; }
    ....[snipped] long candidte list

  • The statement is like:

         if(QObject::connect(m_qtmr, SIGNAL(timeout()),
                              this, SLOT(update()) )==false) {
          throw Error(ECONNREFUSED) ;

    m_qtmr is a QTimer instance
    *this is a subclass of QLabel

  • Lifetime Qt Champion

    QObject::connect() now returns a QMetaObject::Connection and no boolean. So you have to rewrite your statement a little bit to use the operator bool():

    if(!QObject::connect(m_qtmr, SIGNAL(timeout()), this, SLOT(update()) ))

    Or even better use the new signal/slot syntax:

Log in to reply