저는 QT를 배우고 몇 가지 예제를 시도하고 있습니다.슬롯 기능이 호출되지 않음
버튼을 눌렀을 때 라벨이 사라지고 동일한 버튼을 다시 누르면 나타나는 대화 상자를 만들려고합니다.
다음은 코드입니다.
#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();
}
작동하지 않습니다. 테스트 버튼을 누를 때마다 아무 일도 일어나지 않습니다. 하지만 신호 슬롯 연결을 QObject::connect(testButton, SIGNAL(clicked(bool)), testLabel, SLOT(setVisible(bool)));
으로 변경하면 레이블이 사라집니다.
그렇다면 왜 "토글 된"신호로 작동하지 않는 것일까 요? 내가 추측하는 바는 그 신호를 찾을 수 없다는 것입니다. 너희들 빛을 던질 수 있니?