I'm working on QT application where the user will enter their information into several QLineEdits. They then will click son a Submit button. I would like a QMessageBox to appear asking if they would like to confirm their information(OK) or cancel. I want the messagebox to show the information they entered so that they can check to see if it's accurate. Here's my code so far:
QString infoStr = (ui->lastEdit->text() + ", " + ui->firstEdit->text() + "\n" + ui->addressEdit->text() + "\n" + ui->cityEdit->text() + ", " + ui->stateBox->currentText() + " " + ui->zipEdit->text());
switch( QMessageBox::question(
this,
tr("Confirm"),
tr(infoStr&),
QMessageBox::Ok |
QMessageBox::Cancel ))
{
case QMessageBox::Ok:
QMessageBox::information(this, "OK", "Confirmed");
break;
case QMessageBox::Cancel:
//Cancel
break;
}
I'm new to QT and C++. Anything suggestions would be greatly appreciated.
You should read a proper book on C++. For this, you just need to pass the string as the argument, translating is probably not what you want to happen, and &
is just a syntax error:
QMessageBox::question(
this, tr("Confirm"), infoStr, QMessageBox::Ok | QMessageBox::Cancel
);