PDA

View Full Version : connect() returns true but slot not called



OriginalCopy
4th November 2007, 14:05
connect() on the line 19 returns true, all the widgets are set up properly, so the line 20 works, yet the slot is never called. Why ? Where did I do a mistake ?

#include "irc_settings.h"
#include "MainWindow.h"
#include <QtGui>
#include <QtDesigner>

IRC_Settings::IRC_Settings( QWidget *parent) : QWidget(parent) {
dbg() << "setting up irc settings form";
QFormBuilder builder;
QFile file(":/forms/irc_settings.ui");
file.open(QFile::ReadOnly);
QWidget *myWidget = builder.load(&file, this);
file.close();

lineEdit_new_nickname = qFindChild<QLineEdit*>(this,"lineEdit_new_nickname");
lineEdit_new_nickname->setText("foo");
listWidget_nicknames = qFindChild<QListWidget*>(this,"listWidget_nicknames");
toolButton_add_nickname = qFindChild<QToolButton*>(this,"toolButton_add_nickname");

dbg() << "connecting toolButton_add_nickname to listWidget_nicknames" << connect(toolButton_add_nickname,SIGNAL(triggered(Q Action*)),this,SLOT(slot_add_new_nickname(QAction* )));
listWidget_nicknames->addItem(lineEdit_new_nickname->text());
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(myWidget);
setLayout(layout);
}
void IRC_Settings::slot_add_new_nickname(QAction* action) {
dbg() << "adding new nickname:" << lineEdit_new_nickname->text();
listWidget_nicknames->addItem(lineEdit_new_nickname->text());
}

IRC_Settings::~IRC_Settings() {

}

wysota
4th November 2007, 17:44
Did you trigger the toolButton_add_nickname button after making the connection?

OriginalCopy
4th November 2007, 18:00
sure, I do it after I see "connecting toolButton_add_nickname to listWidget_nicknames true" on the stderr

wysota
4th November 2007, 18:08
By clicking on it? Could you connect the clicked() signal as well and see if it works?

OriginalCopy
4th November 2007, 18:19
that works. I'll use that and I'm going to submit a bug report to trolltech (again). Thank you

wysota
4th November 2007, 18:28
Bug report about what? The fact that a signal is not emitted doesn't mean it's a bug. If you didn't associate any action object with the button, I don't see a reason why you connect to the signal and expect it to be emitted. The docs state the signal is related to associated actions (if you use addAction() and/or setDefaultAction() on the button, the signal will probably get emitted).

pherthyl
4th November 2007, 19:54
that works. I'll use that and I'm going to submit a bug report to trolltech (again). Thank you
Wysota is right. This is not a bug. If you don't have any QActions added to your tool button you won't get the triggered signal.

Triggered is when you have multiple actions for one buttons, like this:


colorButton = new QToolButton(this);
colorButton->setPopupMode(QToolButton::InstantPopup);
colorButton->addAction(textColorAct);
colorButton->addAction(itemColorAct);
colorButton->setDefaultAction(textColorAct);
connect(colorButton, SIGNAL(triggered(QAction*)), this, SLOT(onColorActionTriggered(QAction*)));