Qt5.9.6调试QMessageBox::warning()报错

Qt5.9.6中QMessageBox::warning()使用中报错;

error: no matching function for call to QmessageBox::warning(…………

我的源程序是:

QMessageBox::warning(this, "警告", "采集卡连接失败", QMessageBox::Yes, QMessageBox::Yes);

始终出现上方的报错信息,更改中间的字符串格式,还是出错;

注意事项:

1,注意大小写;

QMessageBox的warning和Warning两个方法都存在,注意区分大小写,以大写格式调用小写格式会提示参数错误,反之亦然;

2,看函数原型:

information原型:

StandardButton QMessageBox::information(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton) [static]
  • 第一个参数是父控件指针
  • 第二个参数是标题
  • 第三个参数是内容
  • 第四个参数是窗口里面要多少个按钮(默认为OK)
  • 第五个参数指定按下Enter时使用的按钮。(默认为NoButton,此时QMessageBox会自动选择合适的默认值。)

3,看示例:

QMessageBox::warning(NULL, "warning", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);

为什么第一个参数是NULL?

更改我的写法中

QMessageBox::warning(NULL, "警告", "采集卡连接失败", QMessageBox::Yes, QMessageBox::Yes);

再次编译,成功!

不甚很明白原因。后期深入理解,先写程序吧!

发布了11 篇原创文章 · 获赞 10 · 访问量 5707

猜你喜欢

转载自blog.csdn.net/bxlover007/article/details/104834588