您的位置:首页 > 编程语言 > Qt开发

Qt学习笔记0405

2016-04-05 18:25 447 查看
#include <QtGui>
#include <QMessageBox>
#include <QApplication>
#include <QInputDialog>

int main (int argc, char* argv[]) {                                          //1
QApplication app(argc, argv);                                            //2
QTextStream cout(stdout);                                                //3

int answer = 0;                                                          //4

do {
int factArg = 0;
int fact(1);
factArg = QInputDialog::getInt(0,
"Factorial Calculator",
"Factorial of:",
1);                                   //5

cout << "User entered: " << factArg << endl;

int i=2;
while (i <= factArg) {
fact = fact * i;
++i;
}

QString response = QString("The factorial of %1 is %2.\n%3")
.arg(factArg).arg(fact)
.arg("Compute another factorial?");                              //6

answer = QMessageBox::question(0,
"Play again?",
response,
QMessageBox::Yes | QMessageBox::No);  //7

} while (answer == QMessageBox::Yes);                                    //8

return EXIT_SUCCESS;
}

/*
1 主函数的开始,并返回int
2 所有GUI应用的开端
3 创建模拟的标准输出cout
4 用于DO循环的判定
5 定义一个整型数据输入对话框(QInputDialog::​getInt)
6 .arg可作为替换符,arg()将替换QString中的 %n (%1 %2 %3 ...%9)
7 信息框其中一种:QMessageBox::question的形式
8 通过位运算来判定循环条件
*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Qt