对于Qt中const函数不能emit信号的问题

对于这样一个函数
const RecipePoint &RecipeManager::getPoint(int index) const
内部是不允许emit信号的
这里我们用的信号是这样的

点击查看代码
signals:
    void recipeValidationFailed(const QString& error);  // 非const成员函数
而我们的信号在Qt中是被规定为了一种成员函数,并且C++规定了: 在 const 成员函数中,只能调用 const 成员函数,不能调用非 const 成员函数。 所以这个信号是非const成员函数,当然不能在这个const函数中进行发射信号emit

posted on 2026-07-25 23:22  dd_l  阅读(0)  评论(0)    收藏  举报