【c++】QT 信息框
需要头文件:
#include <QMessageBox>
用到了qDebug来调试输出信息,需要把这个头文件也加上
#include "qdebug.h"
普通信息框:
QMessageBox::information(this,"信息框","普通的信息框");
错误提示信息框
QMessageBox::critical(this,"错误","hello");
警告图标信息框:
QMessageBox::warning(this,"警告","警告图标的信息框");
询问信息框
QMessageBox::question(this,"问你个事","你有对象吗",QMessageBox::Ok|QMessageBox::Cancel);
触发回调写法:
void MainWindow::on_actionmessagebox_triggered()
{
//点击了ok就打印信息
if(QMessageBox::Ok==QMessageBox::question(this,"问你个事","你有对象吗",QMessageBox::Ok|QMessageBox::Cancel)){
qDebug()<<"点击了ok";
}else{
qDebug()<<"点击了cancel";
}
}