QMessageBox::information(this, "Title", "Message");
QMessageBox::StandardButton reply = QMessageBox::warning(this, "Title", "Message", QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes) { // do something } else { // do something else }
QMessageBox msgBox(this); msgBox.setWindowTitle("Title"); msgBox.setText("Message"); msgBox.setIconPixmap(QPixmap(":/images/customicon.png")); msgBox.setStandardButtons(QMessageBox::Ok); msgBox.exec();This code creates a messagebox with a custom pixmap icon located in the application's resources. The dialog box has a title "Title", message "Message", and a single "Ok" button. In all of these examples, QMessageBox is used to display a dialog box to the user. Depending on the type of message or prompt needed for the application, different types of QMessageBox can be used, such as information, warning, critical, or question message boxes. By using QMessageBox, developers can provide important information or request user confirmation in a simple and intuitive way. QMessageBox is a part of the QtWidgets package library in Qt.