• Qt语法


    1.Qt家目录

    QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/Yeecoh/log.txt", //默认搜索路径(改为家目录相对路径)   
     
    "C:\\Users\\zwc11\\Yeecoh",  //原默认搜索路径(绝对路径)
    
    • 1
    • 2
    • 3
    //QFile file("C:/Users/zwc11/Yeecoh/log.txt");  //工位绝对路径
    //QFile file("%HOMEPATH%/Yeecoh/log,txt");      //使用家目录环境变量,读取失败
    QFile file(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/Yeecoh/log.txt"); //选择要读取的文件(使用Qt家目录语法)
    
    • 1
    • 2
    • 3

    2.Qt正则表达式:QRegExp类
    ①exactMatch()函数

     QRegExp rx("(.*Debug.*)|(.*Info.*)|(.*Warning.*)|(.*Critical.*)|(.*Fatal.*)");
            QString str(line);
            if(rx.exactMatch(str)) {    //判断目标与正则表达式是否匹配
    
    • 1
    • 2
    • 3
    void LogWidget::on_pushButton_clicked()
    {
        QString displayString;
      //QFile file("C:/Users/zwc11/Yeecoh/log.txt");  //工位绝对路径
      //QFile file("%HOMEPATH%/Yeecoh/log,txt");      //使用家目录环境变量,读取失败
        QFile file(QStandardPaths::writableLocation(QStandardPaths::HomeLocation)+"/Yeecoh/log.txt"); //选择要读取的文件(使用Qt家目录语法)
        if(!file.open(QIODevice::ReadOnly | QIODevice::Text))
        {
            //qDebug()<<"Can't open the file!";
        }
        while(!file.atEnd())
        {
            QByteArray line = file.readLine();
            QRegExp rx("(.*Debug.*)|(.*Info.*)|(.*Warning.*)|(.*Critical.*)|(.*Fatal.*)");
            QString str(line);
            if(rx.exactMatch(str)) {    //判断目标与正则表达式是否匹配
                //qDebug()<< str;
                displayString.append(str);
            }
            else{
                //什么也不做,不显示内容
            }
        }
           ui->textEdit->clear();
           ui->textEdit->setPlainText(displayString);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26

    3.解决汉字乱码问题u8

    qDebug()<<u8"连接打印机失败";
    
    • 1
    QString str = u8"测试";
    
    • 1
  • 相关阅读:
    【软件工程】作业3
    破天荒呀!小杜微信有名额了
    计算机等级考试—信息安全三级真题二
    OnlyOffice documentType类型值
    linux ifconfig命令:显示或设置网络设备参数信息
    为什么实际开发中不推荐使用外键?
    分享两个小技巧,让你的PPT看起来更高级
    【Pandas包】-文章汇总
    软件安全性测试要点有哪些?常用软件安全测试工具分享
    循环神经网络(RNN)
  • 原文地址:https://blog.csdn.net/Edward1027/article/details/125522130