• 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
  • 相关阅读:
    uni-app 在已有的数据对象中动态添加更多的数据对象
    C. Almost All Multiples(贪心 + 思维)
    三端sonar记录
    2023秋招—大数据开发面经—联友科技
    Scheduling in Kubernetes
    车间调度问题总结笔记二——AGV调度
    Qt样式表之 QSS 语法介绍;QLineEdit、
    大模型训练之加速篇 -> peft(Lora) -> accelerator -> deepspeed (Zero)
    ioremap()
    PHP7.X 版本新特性摘选
  • 原文地址:https://blog.csdn.net/Edward1027/article/details/125522130