View Full Version : about signals and slots
Sandip
15th July 2008, 12:22
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
MrShahi
15th July 2008, 13:22
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 ............;)
wysota
15th July 2008, 13:30
Can we see the exact connect() statements?
Sandip
15th July 2008, 13:46
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.
QMyToolbar::QMyToolbar(QWidget *)
{
m_action = addAction(QIcon(tr("image.png")),tr("Start/Stop"));
connect(m_action, SIGNAL(toggled(bool )), this, SIGNAL(workingToggle(bool)));
}
In MyWidget class file.
QMyToolbar * MyWidget::m_spClockToolbar = NULL;
MyWidget::MyWidget(QWidget *parent)
{
if(m_spClockToolbar == NULL)
{
m_spClockToolbar = new QClockToolBar();
}
connect(m_spClockToolbar, SIGNAL(workingToggle(bool)), this, SLOT(startWork(bool )));
}
m_spClockToolbar is a static member;
Sandip
15th July 2008, 13:50
Hi wysota,
I got answer in different way.
I changed one line.
m_action = addAction(QIcon(tr("image.png")),tr("Start/Stop"), this, SIGNAL(workingToggle(bool)));
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
aamer4yu
15th July 2008, 14:02
Probably you were using a wrong signal - toggled() .
Try trigerred() instead of toggled() and see if it works :)
wysota
15th July 2008, 15:20
toggled() works only for checkable (two-state) actions and yours seems to be a single-state one.
Sandip
15th July 2008, 15:32
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
connect(m_action, SIGNAL(changed( )), this, SIGNAL(checkslot()));
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.
wysota
15th July 2008, 16:31
changed() signal is for something completely different...
Sandip
15th July 2008, 17:02
Yaa, you are right.
Thanks a lot!
Sorry that was my mistake.
Regards,
Sandip
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.