2

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.

Dylan
  • 63
  • 2
  • 9
  • [a bit offtopic] Having an "OK/Cancel" dialog for confirmation is generally a bad design. A more proper solution is Undo. You do not want to interrupt the normal flow. Besides, people just hit OK without reading anyway (well-established fact), so there is no benefit to the dialog anyway. – MSalters Jul 04 '11 at 11:44

1 Answers1

3

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
);
Community
  • 1
  • 1
Cat Plus Plus
  • 125,936
  • 27
  • 200
  • 224
  • Thanks! That answers it for me. I knew it was something stupid I was doing. Like I said, I'm new to C++. Thanks again. – Dylan Jul 03 '11 at 00:10