开发者

Is is possible to pass a QString to a QMessageBox?

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 informati开发者_JAVA技巧on 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
);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜