Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-60539

Setting object of **std::function** as parameter for signal and slot build error

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • P2: Important
    • None
    • 5.7.0
    • Build tools: moc
    • None
    • Windows 10x64. Qt 5.7.0. Compiler : MinGW 32 bit.

    Description

      Hi!
      How to set object of *std::function* as parameter for signal and slot?

      Example:

      signals:
          void sendSetProcFunc(const std::function<void (const QImage &,
                                                     QList<QPolygon> &,
                                                     QList<QImage> &)>
                           &procFunc);
      
      ...................................
      public slots:
          void onSetProcFunc(const std::function<void (const QImage &,
                                                     QList<QPolygon> &,
                                                     QList<QImage> &)>
                           &procFunc);
      

      Building in Qt 5.7 with MinGW_32bit gives next errors:

      debug\moc_QtCVGUI.cpp: In static member function 'static void QtCVGUI::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)':
      debug\moc_QtCVGUI.cpp:131:128: warning: type qualifiers ignored on function return type [-Wignored-qualifiers]
               case 2: _t->sendSetProcFunc((*reinterpret_cast< const std::function<const void( QImage&,QList<QPolygon>&,QList<QImage>&)>(*)>(_a[1]))); break;
                                                                                                                                      ^
      debug\moc_QtCVGUI.cpp:131:142: error: no matching function for call to 'QtCVGUI::sendSetProcFunc(const std::function<const void(QImage&, QList<QPolygon>&, QList<QImage>&)>&)'
               case 2: _t->sendSetProcFunc((*reinterpret_cast< const std::function<const void( QImage&,QList<QPolygon>&,QList<QImage>&)>(*)>(_a[1]))); break;
                                                                                                                                                    ^
      In file included from debug\moc_QtCVGUI.cpp:9:0:
      ****/QtCVGUI.h:49:10: note: candidate: void QtCVGUI::sendSetProcFunc(const std::function<void(const QImage&, QList<QPolygon>&, QList<QImage>&)>&)
           void sendSetProcFunc(const std::function<void (const QImage &,
                ^
      ****/QtCVGUI.h:49:10: note:   no known conversion for argument 1 from 'const std::function<const void(QImage&, QList<QPolygon>&, QList<QImage>&)>' to 'const std::function<void(const QImage&, QList<QPolygon>&, QList<QImage>&)>&'
      

      Removing of all *const* and setting of *std::function* as usual variable (NOT reference) solve this problem (i.e. make succesful build).
      Why are there such restrictions and how to bypass them?

      void sendSetProcFunc(std::function<void (QImage &,
                                                     QList<QPolygon> &,
                                                     QList<QImage> &)>
                           procFunc);
      

      ----------
      Update:

      I didn't properly check all combinations.
      This builds successfull:

      void sendSetProcFunc(const std::function<void (QImage &,
                                                     QList<QPolygon> &,
                                                     QList<QImage> &)>
                           &procFunc);
      
      
      void onSetProcFunc(const std::function<void (QImage &,
                                                     QList<QPolygon> &,
                                                     QList<QImage> &)>
                           &procFunc);
      

      ----------
      Update:

      Workaround was found https://forum.qt.io/topic/78860/using-std-function-as-parameter-for-slot-and-signal/8

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            Unassigned Unassigned
            crazysiberianscientist crazysiberianscientist
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes