zoukankan      html  css  js  c++  java
  • 20.QT文本文件读写

     1 #include "mainwindow.h"
     2 #include "ui_mainwindow.h"
     3 #include <QFile>
     4 #include <QTextCodec>
     5 #include <QDebug>
     6 
     7 MainWindow::MainWindow(QWidget *parent) :
     8     QMainWindow(parent),
     9     ui(new Ui::MainWindow)
    10 {
    11     ui->setupUi(this);
    12 
    13 
    14     QFile file("F:\QTcode\qtfile\file\1.txt");
    15 
    16 //    //按流读取
    17 //    if(file.open(QIODevice::ReadOnly))
    18 //    {
    19 //        //所有的读取
    20 //        QString allstr = "";
    21 //        char buf[2048]={0};
    22 //        qint64 length;
    23 //         while((length = file.readLine(buf,2048))!=-1)
    24 //         {
    25 //            allstr += buf;
    26 //         }
    27 //         ui->textEdit->setText(allstr);
    28 //    }
    29 //    else
    30 //    {
    31 //        qDebug()<<"open fail";
    32 //    }
    33 
    34     //按文件读取,写入
    35     if(file.open(QFile::WriteOnly|QFile::Truncate|QFile::Append))
    36     {
    37         QTextStream out(&file);//创建文件流
    38         out << "12345" << 3245;
    39 
    40     }
    41     else
    42     {
    43         qDebug()<<"open fail";
    44     }
    45 }
    46 
    47 MainWindow::~MainWindow()
    48 {
    49     delete ui;
    50 }
  • 相关阅读:
    SpringBoot优雅的全局异常处理
    react格式化展示json
    Pycharm调试按钮
    HttpURLConnection和okhttp的使用
    objection自动生成hook代码
    hookString
    python取中位数 位运算
    scrapy mongo pipeline
    xpath tips
    IT日语
  • 原文地址:https://www.cnblogs.com/xiaochi/p/8757651.html
Copyright © 2011-2022 走看看