comparison between distinct pointer types 'QPushButton*' and 'QAbstractButton*' lacks a cast

    Qt5使用QDialogButtonBox

    右击buttonBox 选“ go to slots"  (即转到槽),自动完成槽函数的添加

    private slots;

        void on_buttonbox_clicked(QAbstractButton *button);

    在mainWindow.cpp中实现槽函数(上边的):

    void mainWindow::on_buttonbox_clicked(QAbstractButton *button)

    {
        if(ui->buttonBox->button(QDialogButtonBox::Ok)  == button)   //判断按下的是否为"确定”按钮
        {
            /** Do something */
        }
        else

        {

            /** Do something */

        }

    }

    编译时提示:“comparison between distinct pointer types 'QPushButton*' and 'QAbstractButton*' lacks a cast"或“'QAbstractButton' has not been declared”错误。

    解决方案:在头文件中添加#include <QPushButton>

你可能感兴趣的:(QPushButton,QAbstractButton)