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, lambda and duplicated objects...
Forum Updated to NodeBB v4.3 + New Features

QMetaObject::invokeMethod, lambda and duplicated objects...

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.1k 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.
  • D Offline
    D Offline
    Dariusz
    wrote on 15 Aug 2020, 15:09 last edited by Dariusz
    #1

    Hey

    Here is a rough idea of the code

    testClass::testClass(){
      moveToThread(&workThread); /// thread defined as QThread workThread in h.
      workThread.start()
    }
    
    void testClass::sendMsg(someObject*objPtr){
        QMetaObject::invokeMethod(this,[&](){handleObjectData(objPtr);} ,Qt::QueuedConnection);
    }
    void testClass::handleObjectData(someObject *objPtr){
        qDebug()<<objPtr; /// < this is different object to the one I send above in meta... as if it got copied... why ?
    }
    
    

    For some reason when I try to send function/data from MainThread to testClass that is in different thread than mainThread, QT just copies the object... even tho I'm trying to send pointer...

    Any ideas?

    TIA

    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 15 Aug 2020, 15:47 last edited by
      #2

      How did you check? Since you only pass a pointer no object can be copied here.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • D Offline
        D Offline
        Dariusz
        wrote on 15 Aug 2020, 16:46 last edited by
        #3

        I did print in sendMsg before meta, and after inside handleObjectData, I also checked in debug, the object was copied with invalid values, since I didn't implement object copy constructor, not sure. Its weird to me as I should have passed ptr and not obj... weird !

        1 Reply Last reply
        0
        • C Online
          C Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on 15 Aug 2020, 17:14 last edited by
          #4

          Again: you only pass a pointer - there can't be any implicit copy. Please provide a fully working example. Print out the pointer during sendMsg()

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1

          1/4

          15 Aug 2020, 15:09

          • Login

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