Results 1 to 10 of 10

Thread: about signals and slots

  1. #1
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default about signals and slots

    Hi,

    I am wondering to get the answer of basic question.
    I have connected one signal to another signal. The second signal is connected to one slot.
    My problem is that the slot is not called at all.

    Example,

    connect(<object of qaction>, SIGNAL(changed()), <object of my own toolbar>, SIGNAL(<my own signal>));

    in other class

    connect(<object of my own toolbar>, SIGNAL(<my own signal>), <object of my widget>, SLOT(<slot of my widget>));

    Can you help me to figure out my problem? Please let me know how can fix it.

    Thanks in advance.

    Regards,
    Sandip

  2. #2
    Join Date
    Jan 2008
    Posts
    72
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: about signals and slots

    I think there is object problem .....because which signal you are emiting is not receive by your own slot because it treats as different object ...........
    So you have to think in different way to use that object ............

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: about signals and slots

    Can we see the exact connect() statements?

  4. #4
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: about signals and slots

    Yaa, sure!

    Here, I have pasted the main code.
    If you want it in more details then let me know I will drop the complete code.

    In QMyToolbar class file.

    Qt Code:
    1. QMyToolbar::QMyToolbar(QWidget *)
    2. {
    3. m_action = addAction(QIcon(tr("image.png")),tr("Start/Stop"));
    4. connect(m_action, SIGNAL(toggled(bool )), this, SIGNAL(workingToggle(bool)));
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 
    In MyWidget class file.

    Qt Code:
    1. QMyToolbar * MyWidget::m_spClockToolbar = NULL;
    2.  
    3. MyWidget::MyWidget(QWidget *parent)
    4. {
    5. if(m_spClockToolbar == NULL)
    6. {
    7. m_spClockToolbar = new QClockToolBar();
    8. }
    9. connect(m_spClockToolbar, SIGNAL(workingToggle(bool)), this, SLOT(startWork(bool )));
    10.  
    11. }
    To copy to clipboard, switch view to plain text mode 

    m_spClockToolbar is a static member;
    Last edited by jpn; 15th July 2008 at 19:33. Reason: missing [code] tags

  5. #5
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: about signals and slots

    Hi wysota,

    I got answer in different way.
    I changed one line.

    Qt Code:
    1. m_action = addAction(QIcon(tr("image.png")),tr("Start/Stop"), this, SIGNAL(workingToggle(bool)));
    To copy to clipboard, switch view to plain text mode 

    But may I know what was the wrong with my previous code.
    I look me correct. Please let me know if something is wrong.

    Thanks for immediate reply.

    Regards,
    Sandip
    Last edited by jpn; 15th July 2008 at 19:33. Reason: missing [code] tags

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: about signals and slots

    Probably you were using a wrong signal - toggled() .

    Try trigerred() instead of toggled() and see if it works

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: about signals and slots

    toggled() works only for checkable (two-state) actions and yours seems to be a single-state one.

  8. #8
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: about signals and slots

    I don't think that this is the reason. Because I tried with

    changed signal and my slot which doesn't take any arguments.

    it was similar to
    Qt Code:
    1. connect(m_action, SIGNAL(changed( )), this, SIGNAL(checkslot()));
    To copy to clipboard, switch view to plain text mode 

    i should have tried with triggered()

    is there any special case with changed signal? if yes please let me know so that I can take care of it next time

    thanks all of you for helping me.
    Last edited by jpn; 15th July 2008 at 19:34. Reason: missing [code] tags

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: about signals and slots

    changed() signal is for something completely different...

  10. #10
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: about signals and slots

    Yaa, you are right.

    Thanks a lot!

    Sorry that was my mistake.

    Regards,
    Sandip

Similar Threads

  1. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 11:31
  2. Problem with SpinBox signals and slots
    By ramstormrage in forum Newbie
    Replies: 4
    Last Post: 2nd May 2008, 02:45
  3. signals and slots in plugins
    By anderl in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 14:57
  4. Signals and Slots question
    By Thoosle in forum Qt Programming
    Replies: 5
    Last Post: 5th December 2006, 01:24
  5. Signals and Slots in dll
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 29th March 2006, 09:12

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.