What's wrong in this connection?
Hi, I'm trying to connect one signal with one slot but I can't find the problem. Where can it be?
Code:
QHash<int, QString>::const_iterator it = m_miHashTable.constBegin();
while (it != miHashTable.constEnd())
{
QAction* action
= menu
->addAction
(nameSubmenu
);
bool pleaseWork
= QObject::connect(action,
SIGNAL(QAction::triggered(bool)), action,
SLOT(setVisible
(bool)));
it++;
}
"pleaseWork" is always false (I use to set the breakpoint at it++), I've tried with this slot (it should work because it's a QT default slot...) and with functions declared as private, other declared as private slot, with or without parameters... any hint?
thanks!
Re: What's wrong in this connection?
Quote:
void QAction::triggered ( bool checked = false ) [signal]
This signal is emitted when an action is activated by the user; for example, when the user clicks a menu option, toolbar button, or presses an action's shortcut key combination, or when trigger() was called. Notably, it is not emitted when setChecked() or toggle() is called.
If the action is checkable, checked is true if the action is checked, or false if the action is unchecked.
Quote:
visible : bool
This property holds whether the action can be seen (e.g. in menus and toolbars).
If visible is true the action can be seen (e.g. in menus and toolbars) and chosen by the user; if visible is false the action cannot be seen or chosen by the user.
Actions which are not visible are not grayed out; they do not appear at all.
By default, this property is true (actions are visible).
try this:
Code:
bool pleaseWork
= QObject::connect(action,
SIGNAL(triggered
(bool)), action,
SLOT(setVisible
(bool)));
Re: What's wrong in this connection?
Drop the "QAction::" part in signal signature.
Re: What's wrong in this connection?
now seems to work... it's strange, I added that QAction when it wasn't working and I was searching the problem; well, now I just need your help to discover why my cutomized slot does not work... :S
Code:
QHash<int, QString>::const_iterator it = m_miHashTable.constBegin();
while (it != miHashTable.constEnd())
{
QAction* action
= menu
->addAction
(nameSubmenu
);
bool pleaseWork
= QObject::connect(action,
SIGNAL(triggered
(bool)),
this,
SLOT(changeStatus
(bool)));
it++;
}
header file (after public and private, in other projects it worked fine, and I've tried as private and public and public slots and private slots)
Code:
private slots:
void changeStatus(bool a);
Code:
void CIAguja::changeStatus(bool a)
{
}
thanks again!
Re: What's wrong in this connection?
did you had an Q_OBJECT macro in your class defination?
Re: What's wrong in this connection?
Re: What's wrong in this connection?
.
..
...
well, so many hours trying and trying and trying and, in the end, it's true, I didn't have the macro in that, and only that (because I use a template!) new header file... working the fridays-afternoon, and having to repair the code the mondays-morning is definitly bad for the health of the code :S