Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Signal-slot and rvalue references

Signal-slot and rvalue references

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 3.3k Views
  • 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.
  • M Offline
    M Offline
    Meteorhead
    wrote on last edited by
    #1

    Hi!

    I would like to ask how exactly the signal-slot mechanism is implemented under the hood, and whether it makes use of rvalue references if I toss one at it. I only ask because I am developing an application that will pass potentially large objects around, or simply ones that take time to initialize. I do know however that these objects will be destroyed once the emit signal has been issued, and I would like to make use of move ctors, either those that I write, or those that are predefined by Qt (if there are any). Custom made ctors would include GPU mem object wrapper classes, and I would expect objects lie QByteStream and alike to have their own.

    Are these feature supported, or is passing std::shared_ptr (or QSharedPointer) the best way to pass on large objects like this?

    1 Reply Last reply
    0
    • S Offline
      S Offline
      Santosh Reddy
      wrote on last edited by
      #2

      You can pass all the types of variables in a signal, just as if it were directly calling the function. One important thing to note while using signals across threads in asynchronous mode is that the variables better be passes by value, or else you will need to use an eplicit mechanism to make the passed data valid until all the slots are executed.

      SS

      1 Reply Last reply
      0
      • M Offline
        M Offline
        Meteorhead
        wrote on last edited by
        #3

        And how does multiple slots connected to a signal work? If I understand it correctly, hooking up multiple slots to a signal is valid even when using RValue refs, it will only result in erronous behavior, since after the first invocation, the object has already had it's contents moved out.

        Passing references I guess is ok, so long as the object passed will not be destroyed (eg. it is a member of the wrapping object) until the actual call is finished.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Santosh Reddy
          wrote on last edited by
          #4

          bq. Passing references I guess is ok, so long as the object passed will not be destroyed (eg. it is a member of the wrapping object) until the actual call is finished.
          Correct

          SS

          1 Reply Last reply
          0

          • Login

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