执行我的应用程序时会出现一些警告消息:
QMetaObject::connectSlotsByName: No matching signal for on_actionUndo_triggered()
,
QMetaObject::connectSlotsByName: No matching signal for on_actionRedo_triggered()
我已经对我创建的信号和插槽实施了规则void on_objectName_signalName(signalParameters);
,但我不知道为什么会出现这些消息,请注意信号和插槽工作正常。
宣言:
class Widget : public QWidget {
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
private:
Ui::Widget *ui;
QAction *actionUndo;
QAction *actionRedo;
private slots:
void on_actionUndo_triggered();
void on_actionRedo_triggered();
};
定义:
Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) {
ui->setupUi(this);
QVBoxLayout *layout = new QVBoxLayout(this);
QMenuBar *menuBar = new QMenuBar();
QMenu *editMenu = new QMenu("&Edit");
menuBar->addMenu(editMenu);
this->actionUndo = new QAction("&Undo", editMenu);
this->actionUndo->setShortcut(QKeySequence::Undo);
QObject::connect(this->actionUndo, SIGNAL(triggered()), this, SLOT(on_actionUndo_triggered()));
this->actionRedo = new QAction("&Redo", editMenu);
this->actionRedo->setShortcut(QKeySequence::Redo);
QObject::connect(this->actionRedo, SIGNAL(triggered()), this, SLOT(on_actionRedo_triggered()));
editMenu->addAction(this->actionUndo);
editMenu->addAction(this->actionRedo);
this->layout()->setMenuBar(menuBar);
}
Widget::~Widget() {
delete ui;
}
void Widget::on_actionUndo_triggered() {
}
void Widget::on_actionRedo_triggered() {
}