Labels: style blog http OS ar file 2014 Div sp
Addition operations implemented by 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));
}
To open a file window and read the content
void Widget::on_pushButton_clicked()
{
Qstring filename = qfiledialog: getopenfilename (0, "open ");
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);
}
Implements the window for saving files and writes its content
void Widget::on_pushButton_2_clicked()
{
Qstring filename = qfiledialog: getsavefilename (0, "save ");
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);
}
Use QT to implement your own IDE and easy language
See instructor Zhu's video
From Weizhi note (wiz)
9.7 QT self-cultivation