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. Scope of objects sent in connect statements

Scope of objects sent in connect statements

Scheduled Pinned Locked Moved Unsolved General and Desktop
scopeconnectsignal&slot
2 Posts 2 Posters 1.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.
  • R Offline
    R Offline
    RDiGuida
    wrote on 29 Jan 2016, 16:14 last edited by
    #1

    Hello, I am not sure about the lifespan of objects created in a function and emitted in a signal.

    int foo()
    {
        QStringList str
        //Calculations and other stuff...
       
       emit CalculationsDone(str)
       return 0;
    }
    
    void someSlot(const QStringList&)
    {
    ...
    }
    
    int bar()
    {
        connect(&objectWithFunctionFoo,SIGNAL(CalculationsDone(const QStringList&)),this,SLOT(someSlot(const QStringList&)));
    }
    

    What is the lifespan of str. Does it wait for SLOT to complete before going out of scope?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 29 Jan 2016, 16:19 last edited by mrjj
      #2

      hi
      "
      When a signal is emitted, the slots connected to it are usually executed immediately, just like a normal function call. When this happens, the signals and slots mechanism is totally independent of any GUI event loop. Execution of the code following the emit statement will occur once all slots have returned. The situation is slightly different when using queued connections; in such a case, the code following the emit keyword will continue immediately, and the slots will be executed later."

      http://doc.qt.io/qt-5.5/signalsandslots.html

      1 Reply Last reply
      0

      1/2

      29 Jan 2016, 16:14

      • Login

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