slot function not getting called

Posted by chappar on Stack Overflow See other posts from Stack Overflow or by chappar
Published on 2010-03-09T07:20:21Z Indexed on 2010/03/09 7:36 UTC
Read the original article Hit count: 320

Filed under:
|

I am learning QT and trying out some examples.

I am trying to make a dialog that disappears a label when a button is pressed and makes it appear when the same button is pressed again.

Below is the code.

#include <QApplication>
#include <QPushButton>
#include <QLabel>
#include <QDialog>
#include <QObject>
#include <QHBoxLayout>

int main(int argc, char ** argv)
{
   QApplication app(argc, argv);
   QDialog *dialog = new QDialog;
   QPushButton *testButton = new QPushButton(QObject::tr("test"));   
   QLabel * testLabel = new QLabel (QObject::tr("test"));
   QHBoxLayout * layout = new QHBoxLayout;
   layout->addWidget(testButton);
   layout->addWidget(testLabel);
   QObject::connect(testButton, SIGNAL(toggled(bool)), testLabel, SLOT(setVisible(bool)));
   dialog->setLayout(layout);
   dialog->show();
   return app.exec();
}

It is not working. Whenever i press the test button nothing happens. But if i change the signal slot connections as QObject::connect(testButton, SIGNAL(clicked(bool)), testLabel, SLOT(setVisible(bool))); it makes the label disappear.

So, why it is not working with signal "toggled". What i am guessing is, it is not able to find that signal. Can you guys throw some light?

© Stack Overflow or respective owner

Related posts about qt4

Related posts about signals-slots