QT自我的修养
QT实现的加法运算:
void Widget::on_pushButton_clicked()
{
QString s1 = ui->lineEdit->text();
QString s2 = ui->lineEdit_2->text();
int sum = s1.toInt(0,10) + s2.toInt(0,10);
ui->textEdit->setText(QString::number(sum , 10));
}
实现打开文件的窗口,并且读取内容
void Widget::on_pushButton_clicked()
{
QString filename = QFileDialog::getOpenFileName(0,"打开");
if (filename.isEmpty())
return;
FILE *fp = fopen(filename.toStdString().data(),"r");
if (!fp)
return;
char buf[1024];
QString str;
while (!feof(fp))
{
fgets(buf , sizeof(buf) , fp);
str += buf;
}
ui->textEdit->setText(str);
}
实现保存文件的窗口,并且写其内容
void Widget::on_pushButton_2_clicked()
{
QString filename = QFileDialog::getSaveFileName(0,"保存");
if(filename.isEmpty())
return;
FILE *fp = fopen(filename.toStdString().data(),"w");
if (!fp)
return;
const char *str = ui->textEdit->toPlainText().toStdString().data();
fputs(str,fp);
fclose(fp);
}
用QT实现自己的IDE和易语言
见朱老师视频