Results 1 to 3 of 3

Thread: Nested signals and slots

  1. #1
    Join Date
    Jul 2006
    Location
    Coimbatore,India
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Nested signals and slots

    hai friends,

    I am suffering the following problem in my application.

    Code:

    Header file:

    class Sample: public QDialog
    {

    private slots:

    void fun1();

    void fun2();

    };

    cpp file:

    Sample::Sample
    {

    connect(&object,SIGNAL(clicked()),this,SLOT(fun1() ));
    }

    void Sample::fun1()
    {
    connect(&object,SIGNAL(clicked()),this,SLOT(fun2() ));
    }

    void Sample::fun2()
    {

    //
    // to run some instruction here
    }


    Ok, run this program,

    First time,
    Main widget( Clicked) -> fun1() -> clicked -> fun2() then return to main widget
    Here ,its work fine.

    Second time,

    Main widget( Clicked) -> fun1() -> clicked -> fun2() then again call fun2() , then return to main widget
    3rd time,
    the function2 called 3 times.

    Nth time ,

    The function2 called n times.


    i.e,
    the last function ( fun2() ) called number of times automatically ( current + prev ).


    Can you tell me ,what is the problem in nested signals and slots ?
    Vichu

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Nested signals and slots

    Quote Originally Posted by vishva
    Can you tell me ,what is the problem in nested signals and slots ?
    The problem is that you are forming a new connection every time the fun1() slot is called. The old connections naturally remain unless you disconnect them.

    I'm not sure what are you trying to achieve, but maybe you need something like this:
    Qt Code:
    1. void Sample::fun1()
    2. {
    3. disconnect(&object,SIGNAL(clicked()),this,SLOT(fun1() ));
    4. connect(&object,SIGNAL(clicked()),this,SLOT(fun2() ));
    5. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    vishva (18th August 2006)

  4. #3
    Join Date
    Jul 2006
    Location
    Coimbatore,India
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Nested signals and slots

    hi jpn,

    i sloved that problem using disconnect() in fun2(). so it works fine.

    Thanks
    Vichu

Similar Threads

  1. help with signals and slots
    By superutsav in forum Qt Programming
    Replies: 3
    Last Post: 4th May 2006, 12:49
  2. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 08:12
  3. Order of signals and slots
    By Morea in forum Newbie
    Replies: 1
    Last Post: 26th February 2006, 22:09
  4. howto debug connection of signals and slots?
    By jh in forum Qt Programming
    Replies: 11
    Last Post: 24th February 2006, 09:30
  5. Problem with Signals and Slots
    By Kapil in forum Newbie
    Replies: 11
    Last Post: 15th February 2006, 11:35

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.