QT自我的修养

QT实现的加法运算:
  1. void Widget::on_pushButton_clicked()
  2. {
  3. QString s1 = ui->lineEdit->text();
  4. QString s2 = ui->lineEdit_2->text();
  5. int sum = s1.toInt(0,10) + s2.toInt(0,10);
  6. ui->textEdit->setText(QString::number(sum , 10));
  7. }


实现打开文件的窗口,并且读取内容
  1. void Widget::on_pushButton_clicked()
  2. {
  3. QString filename = QFileDialog::getOpenFileName(0,"打开");
  4. if (filename.isEmpty())
  5. return;
  6. FILE *fp = fopen(filename.toStdString().data(),"r");
  7. if (!fp)
  8. return;
  9. char buf[1024];
  10. QString str;
  11. while (!feof(fp))
  12. {
  13. fgets(buf , sizeof(buf) , fp);
  14. str += buf;
  15. }
  16. ui->textEdit->setText(str);
  17. }

实现保存文件的窗口,并且写其内容
  1. void Widget::on_pushButton_2_clicked()
  2. {
  3. QString filename = QFileDialog::getSaveFileName(0,"保存");
  4. if(filename.isEmpty())
  5. return;
  6. FILE *fp = fopen(filename.toStdString().data(),"w");
  7. if (!fp)
  8. return;
  9. const char *str = ui->textEdit->toPlainText().toStdString().data();
  10. fputs(str,fp);
  11. fclose(fp);
  12. }

用QT实现自己的IDE和易语言

见朱老师视频







posted @ 2014-09-15 00:10  我爱背单词  阅读(143)  评论(0编辑  收藏  举报