覆盖 类 中的 Qt 函数

Overriding Qt function in classes

我有一个 QDialog 类型的简单对话框。当用户单击“确定”按钮时,我想在关闭表单并返回给调用者(主表单)之前进行一些验证。

我试图在我的 "CustomDialog.cpp" 文件中添加以下代码:

void CustomDialog::accept(){
  // My code...
}

但是我得到这个错误:

error: virtual function 'accept' has different calling convention attributes ('void ()') than the function it overrides (which has calling convention 'void () attribute((thiscall))')

我做错了什么?我是否也需要在 CustomDialog.hpp 中添加一些内容?

在您的 .hpp 中,您应该在 CustomDialog class 中声明 accept() 方法。即 void accept() override;public slots.