Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Signals and Slots with Qtoolbutton

Tags:

c++

qt

qt4

I have created a ToolButton with my qt designer and Im trying to connect it to a slot. I wrote this

connect(ui->toolButton_addfiles, SIGNAL(triggered()), this, SLOT(changeDirectory()));

Im able to run the program but when I press the button I see the following log into my qt Application Output :

   Object::connect: No such signal QToolButton::triggered() in ../RightDoneIt/rightdoneit.cpp:10
    Object::connect:  (sender name:   'toolButton_addfiles')
    Object::connect:  (receiver name: 'RightDoneIt')
  • If I change the toolButton_addfile to some action like (actionChange_addfile) it will work fine.

How can I make this connection work ?

like image 620
Sharethefun Avatar asked Oct 14 '25 23:10

Sharethefun


2 Answers

As the error says, there's no signal triggered() but triggered(QAction*) in the QToolButton.

Edit In the connect function you must have the signal signature like triggered(QAction*) since QToolButton class has no signal triggered() (with no parameter) declared

like image 85
Patrice Bernassola Avatar answered Oct 17 '25 12:10

Patrice Bernassola


You could use the auto-connection process of Qt.

In the class referencing your UI, create a slot called :

on_toolButton_addfiles_clicked();

Exemple :

See : A Dialog With Auto-Connect

class ImageDialog : public QDialog, private Ui::ImageDialog
{
    Q_OBJECT

public:
    ImageDialog(QWidget *parent = 0);

private slots:
    void on_okButton_clicked();
};

Hope this helps !

Edit : No triggered signals in qAbstractButton. See http://doc.qt.nokia.com/4.7/qabstractbutton.html

like image 25
Andy M Avatar answered Oct 17 '25 12:10

Andy M