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

Creating connections/invoking methods using QPointer

XMLWordPrintable

    • Icon: Suggestion Suggestion
    • Resolution: Out of scope
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • None
    • Core: Object Model
    • None
    • All

      In multi-threaded applications it may be sometimes useful to create connections between objects created in different threads, or invoking methods of an object that lives in another thread and can be destroyed at any time.

      Here is an example from QtNfc:

      • The main thread contains Manager object
      • Manager creates a Worker object, connects signal cardCreated(QPointer<Card>) or Worker to onCardCreated(QPointer<Card>) of Manager.
      • A worker thread is then started with an event loop, Worker is moved to that thread.
      • Worker creates an instance of Card and emits cardCreated().
      • onCardCreated() of Manager is executed, the manager wants to create Target object that is connected to Card.

      Right now the last step requires some other protocol to ensure that Card object is not destroyed before Manager finises all the connection. Extending QObject::connect() to accept QPointer arguments would significantly simplify the use case. QMetaObject::invokeMethod() extended with QPointer support is another API that may be useful in similar cases.

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

            thiago Thiago Macieira
            ievgenii.meshcheriakov Ievgenii Meshcheriakov
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes