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

Can't define connection type when connecting functions and/or functors

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P4: Low
    • 5.2.0
    • 5.0.0, 5.1.0
    • Core: Event loop
    • None
    • Windows, Linux, QtCreator 2.7.2

    Description

      It it is not possible to define a connection type when connecting a functor/lambda or a function to a signal.
      When I try this pseudocode:

      // Make the status bar visible:
      statusBar()->showMessage( "" );
      QThread *thread = new QThread;
      connect( thread, &QThread::started, [this] {
          statusBar()->showMessage( "Thread started." );
      });
      

      then the lambda is connected with Qt::DirectConnection (qobject.h, line 314) for functors and for functions (qobject.h, line 261). This results in an "QCoreApplication::sendEvent: “Cannot send events to objects owned by a different thread"
      The typical solution would be to specify Qt::QueuedConnection, which is not possible with the current signature. The problem is that functors/functions don't have a thread affinity, and so it's not possible to determine what kind of event transportation mechanism should be used. But the thread affinity of functors/functions can't be changed and so it should be save to store the thread which is calling connect().

      http://qt-project.org/forums/viewthread/29745/

      Attachments

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

        Activity

          People

            ogoffart Olivier Goffart (Woboq GmbH)
            p. most Peter Most
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes