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. QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...
Forum Updated to NodeBB v4.3 + New Features

QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 5 Posters 3.4k 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.
  • jsulmJ jsulm

    @opengpu said in QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...:

    why this works while the slot is const

    Why should it not? data will be const in the called slot. It doesn't matter whether it is const or not in the caller.

    There is no need to register "const Data&". If Data is registered everything else (const, &, *, ...) is simply an "attribute" for an already known type. It is like with the compiler: if the compiler knows what Data is it knows what const Data& is.

    O Offline
    O Offline
    opengpu
    wrote on last edited by
    #21

    @jsulm "const Data&", i think normally it's not safe to pass-by-reference across threads, right?

    VRoninV jsulmJ 2 Replies Last reply
    0
    • O opengpu

      @jsulm "const Data&", i think normally it's not safe to pass-by-reference across threads, right?

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by VRonin
      #22

      @opengpu said in QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...:

      i think normally it's not safe to pass-by-reference across threads, right?

      Depends who you ask. The chair of the C++ standard committee is of the opinion that as STL uses const as implying thread safety* the entire language should conform to that convention. In that case using cons& as argument is safe even across threads. On the other hand it's a jungle out there and it's very easy to break that convention so I would not bet my life on thread safety of const references

      *source: https://herbsutter.com/2013/01/01/video-you-dont-know-const-and-mutable/

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • O opengpu

        @jsulm "const Data&", i think normally it's not safe to pass-by-reference across threads, right?

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #23

        @opengpu said in QMetaObject::invokeMethod pass custom-type called Twice custom-type's copy constructor...:

        it's not safe to pass-by-reference across threads, right?

        @SGaist already explained in this thread that the parameter is copied when using queued connection between threads, so it IS safe...

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1

        • Login

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