Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Using std::unique_ptr<> in a signal/slot argument.
Forum Updated to NodeBB v4.3 + New Features

Using std::unique_ptr<> in a signal/slot argument.

Scheduled Pinned Locked Moved C++ Gurus
c++11 move sema
2 Posts 1 Posters 1.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    laan
    wrote on last edited by
    #1

    Hi,

    I'm trying to send a custom c++ object from a QThread to a slot in the main thread using the standard Qt signal/slot mechanism. I'm registering my custom type using qRegisterMetaType() and it all works well... please see this gist for a short code snippet:

    https://gist.github.com/landersson/11ff00b40cedf5f8f60f

    The problem is, when I add an std::unique_ptr<> member to my custom class, my object is no longer copy-constructible, and qRegisterMetaType() fails. If I use a plain old pointer it works just fine.

    My question is:

    Is there any way to send objects that are moveable (i.e have C++11 move semantics) but are NOT copyable via the Qt signal/slot mechanism?

    1 Reply Last reply
    1
    • L Offline
      L Offline
      laan
      wrote on last edited by
      #2

      After doing some more research, I've realized that, since it should be possible to send a signal to multiple slots, using a unique_ptr in (or as a member of) signal arguments is probably not a good idea, or even possible.

      1 Reply Last reply
      2

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved