qt写一个计算器的代码
时间: 2023-09-12 20:10:33 浏览: 125
Qt计算器代码
当然可以!以下是一个使用Qt编写的简单计算器的示例代码:
```cpp
#include <QApplication>
#include <QGridLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QWidget>
int main(int argc, char *argv[]) {
QApplication app(argc, argv);
QWidget window;
window.setWindowTitle("计算器");
QGridLayout *layout = new QGridLayout(&window);
QLineEdit *display = new QLineEdit();
display->setReadOnly(true);
layout->addWidget(display, 0, 0, 1, 4);
QPushButton *buttons[10];
for (int i = 0; i < 10; ++i) {
buttons[i] = new QPushButton(QString::number(i));
}
layout->addWidget(buttons[7], 1, 0);
layout->addWidget(buttons[8], 1, 1);
layout->addWidget(buttons[9], 1, 2);
layout->addWidget(buttons[4], 2, 0);
layout->addWidget(buttons[5], 2, 1);
layout->addWidget(buttons[6], 2, 2);
layout->addWidget(buttons[1], 3, 0);
layout->addWidget(buttons[2], 3, 1);
layout->addWidget(buttons[3], 3, 2);
layout->addWidget(buttons[0], 4, 0, 1, 3);
QPushButton *addButton = new QPushButton("+");***
阅读全文