我正在学习 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)));
它会使标签消失。
那么,为什么它不适用于“切换”信号。我猜是,它无法找到那个信号。各位大神能不能放个光?