Results 1 to 4 of 4

Thread: One question about the execution of the slot function

  1. #1
    Join Date
    Aug 2008
    Posts
    16
    Thanks
    3

    Exclamation One question about the execution of the slot function

    Hi guys,
    I have a class Test, and there is one normal function funcA(), and a slot function slot():
    void Test::funcA()
    {
    if(m_index != 2)
    {
    //---------------- interrupt
    //DO SOMETHINS
    }
    }

    slot:
    void Test::slot()
    {
    m_index = 2;
    }

    And now I have a question, If when I call function funcA(), and there is a signal which associate with slot: slot() emited, just after execute "if(m_index != 2)" and enter the if state, will the funcA() be interrupted at "---------------- interrupt" and begin to run slot()? if yes, there will be a unpredictable fault!

    Thanks for your suggestions!

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: One question about the execution of the slot function

    Only when the function and the slot are executed in separate threads. In this case, you need to ensure synchronization ie. with QMutex.

  3. #3
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: One question about the execution of the slot function

    Even if signal is emitted from separate thread, the slot() will not execute untill thread running funcA() will return to the event loop.

    And as far as I know there's no way to put two functions of the same object in separate threads

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: One question about the execution of the slot function

    Quote Originally Posted by Spitfire View Post
    Even if signal is emitted from separate thread, the slot() will not execute untill thread running funcA() will return to the event loop.

    And as far as I know there's no way to put two functions of the same object in separate threads
    Of course You can. QObject::connect method have parameter Qt::ConnectionType. You can create direct connection between two threads. Then slot is executed immediately. Not discuss whether it makes sense but it is possible.

Similar Threads

  1. Call a function at a dialog execution
    By Nesbit in forum Qt Programming
    Replies: 5
    Last Post: 20th April 2012, 15:37
  2. Javascript Function execution in html page
    By saeedIRHA in forum Newbie
    Replies: 6
    Last Post: 17th October 2011, 14:01
  3. Replies: 2
    Last Post: 26th August 2011, 09:51
  4. My Slot Function
    By qtoptus in forum Qt Programming
    Replies: 3
    Last Post: 3rd November 2010, 17:38
  5. Signal/Slot execution sequences/preemption
    By xenome in forum Qt Programming
    Replies: 8
    Last Post: 17th September 2009, 23:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.