PDA

View Full Version : What's wrong in this connection?



jano_alex_es
14th September 2009, 08:24
Hi, I'm trying to connect one signal with one slot but I can't find the problem. Where can it be?




QMenu* menu = new QMenu();

QHash<int, QString>::const_iterator it = m_miHashTable.constBegin();
while (it != miHashTable.constEnd())
{
QString nameSubmenu = it.value();
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!

AcerExtensa
14th September 2009, 08:35
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.


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:


bool pleaseWork = QObject::connect(action, SIGNAL(triggered(bool)), action, SLOT(setVisible(bool)));

wysota
14th September 2009, 08:36
Drop the "QAction::" part in signal signature.

jano_alex_es
14th September 2009, 09:22
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



QMenu* menu = new QMenu();

QHash<int, QString>::const_iterator it = m_miHashTable.constBegin();
while (it != miHashTable.constEnd())
{
QString nameSubmenu = it.value();
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)

private slots:
void changeStatus(bool a);


void CIAguja::changeStatus(bool a)
{
}

thanks again!

nish
14th September 2009, 09:28
did you had an Q_OBJECT macro in your class defination?

jano_alex_es
14th September 2009, 09:32
yes, I have it.

jano_alex_es
14th September 2009, 09:36
.
..
...

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