是否可以将 QString 传递给 QMessageBox?
我正在开发 QT 应用程序,用户将在其中将其信息输入到多个 QLineEdit 中。然后他们将单击“提交”按钮。我希望出现一个 QMessageBox 询问他们是否要确认他们的信息(确定)或取消。我希望消息框显示他们输入的信息,以便他们可以检查信息是否准确。到目前为止,这是我的代码:
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;
}
我是 QT 和 C++ 的新手。任何建议将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您应该阅读一本有关 C++ 的正确书籍。为此,您只需传递字符串作为参数,翻译可能不是您想要发生的情况,并且
&
只是一个语法错误: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: