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
QtWS25 Last Chance

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 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
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on 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

      • Login

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