天气与日历 切换到窄版

 找回密码
 立即注册
中国膜结构网
十大进口膜材评选 十大国产膜材评选 十大膜结构设计评选 十大膜结构公司评选
查看: 21|回复: 0

QT上的一个打印调试到文件的函数

[复制链接]
  • TA的每日心情
    开心
    3 天前
  • 签到天数: 82 天

    [LV.6]常住居民II

    1591

    主题

    204

    回帖

    214748万

    积分

    管理员

    积分
    2147483647
    发表于 2024-5-4 19:19:53 | 显示全部楼层 |阅读模式
    1. #include <qtextstream.h>
    2. #include <qdatetime.h>
    3. #include <dlfcn.h>
    4. #include <QFile>
    5. #include <QDir>

    6. /*************************************************
    7. Description:    // 获取函数运行信息
    8. Input:          // func - 函数指针
    9. *************************************************/
    10. QString identify_function_ptr(void* func)
    11. {
    12.     Dl_info info;
    13.     int rc = dladdr(func,&info);
    14.     return info.dli_fname;
    15. }
    16. /*************************************************
    17. Description:    // 打印调试信息到文本文件
    18. Input:          // outSt - 字符 filename - 文件名
    19. *************************************************/
    20. void DPrintfToFile(QString outSt,QString filename)
    21. {
    22.     //默认文件名
    23.     if(filename=="")
    24.     {
    25.         filename = "DebugLog.txt";
    26.     }

    27.     //路径
    28.     QString filePath = identify_function_ptr((void*) identify_function_ptr);
    29.     QFileInfo fileInfo(filePath);
    30.     QString directoryPath = fileInfo.dir().path() + "/" + filename;
    31.     QFile fileError(directoryPath);
    32.     if(fileError.open(QIODevice::ReadWrite|QIODevice::Text|QIODevice::Append)){
    33.         // 将内容写入文件
    34.         QTextStream out(&fileError);
    35.         out.setCodec("UTF-8");
    36.         QDateTime dateTime= QDateTime::currentDateTime();//获取系统当前的时间
    37.         QString strTime = dateTime.toString("yyyy-MM-dd hh:mm:ss");//格式化时间
    38.         out.seek(0);
    39.         out << strTime << ":" << outSt << "\n";
    40.         fileError.close();
    41.     }
    42. }
    复制代码

     

     

     

     

    QT上的一个打印调试到文件的函数
    中国膜结构网打造全中国最好的膜结构综合平台 ,统一协调膜结构设计,膜结构施工,膜材采购,膜材定制,膜结构预算全方位服务。 中国空间膜结构协会合作单位。
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|Archiver|手机版|中国膜结构网_中国空间膜结构协会

    GMT+8, 2024-5-19 07:18 , Processed in 0.059449 second(s), 22 queries .

    Powered by Discuz! X3.5

    © 2001-2024 Discuz! Team.

    快速回复 返回顶部 返回列表