首页 > 其他分享 >QT5.14: 打开文件出错warning: format '%s' expects argument of type 'char*'

QT5.14: 打开文件出错warning: format '%s' expects argument of type 'char*'

时间:2023-10-05 22:13:02浏览次数:42  
标签:QT5.14 format textStream expects filename char file printf type

错误提示信息:

D:\Demo\QT5.14\CH5\CH501\imgprocessor.cpp:158: warning: format '%s' expects argument of type 'char*', but argument 2 has type 'QChar*' [-Wformat=]
printf("file Name:%s\n",filename.data());

原函数代码:

void ImgProcessor::loadFile(QString filename)
{
    printf("file Name:%s\n", filename.data());
    QFile file(filename);
    if(file.open(QIODevice::ReadOnly|QIODevice::Text)){
        QTextStream textStream(&file);
        while(!textStream.atEnd()){
            showWidget->text->append(textStream.readLine());
            printf("read line\n");
        }
        printf("end\n");
    }
}

  

修改后,没有提示:

void ImgProcessor::loadFile(QString filename)
{
    printf("file Name:%s\n", (char*)filename.data());
    QFile file(filename);
    if(file.open(QIODevice::ReadOnly|QIODevice::Text)){
        QTextStream textStream(&file);
        while(!textStream.atEnd()){
            showWidget->text->append(textStream.readLine());
            printf("read line\n");
        }
        printf("end\n");
    }
}

  主要修改句:

   printf("file Name:%s\n", (char*)filename.data());

 

标签:QT5.14,format,textStream,expects,filename,char,file,printf,type
From: https://www.cnblogs.com/samrv/p/17744003.html

相关文章

  • Go - Decoding Data with a Customized Binary Format to Structs
    Problem: Youwanttodecodethecustomizedbinaryformatbacktostructs.Solution: Usetheencoding/binarypackagetotakedatafromthebinaryformatand reconstructstructsfromit. funcmain(){vardataMeterfile,err......
  • Go - Encoding Data to a Customized Binary Format
    Problem: Youwanttoencodestructdatatoacustomizedbinaryformat.Solution: Designyourcustomizedformatandusetheencoding/binarypackagetowritedatainstructstoit. Usinggobhasacoupleofdrawbacks.First,gobissupportedbyGoonlya......
  • Go - Decoding gob Format Data to Structs
    Problem: Youwanttodecodegobformatdatabacktostructs.Solution: Usetheencoding/gobpackagetodecodethegobformatdatabacktostructs. funcread(datainterface{},filenamestring){file,err:=os.Open(&quo......
  • Go - Encoding Data to gob Format Data
    Problem: Youwanttoencodestructsintobinarygobformat.Solution: Usetheencoding/gobpackagetoencodethestructsintobytesthatcanbestoredorsentelsewhere. Theencoding/gobpackageisaGolibrarytoencodeanddecodeabinaryformat.The......
  • mybatis出现错误 java lang NumberFormatException:For input string:A1
    使用mybatis,当使用map传参并且在iftest判断时使用map中所传的参数时,可能会产生如题的报错,具体报错信息见下图:分析这个错误,自己调试也找过度娘,“坚信”自己代码并没问题,但是问题始终无法解决。最后在一个帖子看到说iftest判断时,传入的参数跟匹配的值类型必须一致,于是调整了自己代......
  • Common Certificate Formats
    为什么会有那么多种类的证书?一般而言,不同后缀的证书代表不同的编码、解码规则。要么是不同功能场景,要么是同一个功能只是不同厂商的不同风格罢了。不一一记录了,用到在查吧。Reference数字证书常见格式整理https://blog.csdn.net/zhulianhai0927/article/details/106452521......
  • java.net.ConnectException: Connection refused: no further information
    java.net.ConnectException:Connectionrefused:nofurtherinformation atsun.nio.ch.SocketChannelImpl.checkConnect(NativeMethod)~[na:1.8.0_91] atsun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)~[na:1.8.0_91] atio.netty.channe......
  • Social Infrastructure Information Systems Division, Hitachi Programming Contest
    A-HitachiString满足条件的串即为串长为偶数且相邻两个均为为hi,直接判断即可。代码:#include<iostream>#include<cstdio>#include<cstring>usingnamespacestd;constintN=15;intn;chars[N];intmain(){ scanf("%s",s+1); n=strlen(s+1); if(n&1) ......
  • SQL注入 --【过滤or(包含information、orderby这种也寄了)和and的类型】
    来自:[SWPU2019]Web1详见博客:https://blog.csdn.net/plant1234/article/details/124205120payload如下:查看行数1'/**/group/**/by/**/1,'1......直到1'/**/group/**/by/**/23,'1报错也就是说有22行找出回显点//找出回显点-1'/**/union/**/select/**/1,2,3,4,5,6,7......
  • little information
    SmartBear注册:Account=lsy283718040免费api使用https://blog.csdn.net/zlfjavahome/article/details/127983226https://api.oioweb.cn/ P3210.Postman项目实战以及集合newman和Jenkins持续集成(finishedlistening)https://www.bilibili.com/video/BV11K4y1J7sh/?p=32&spm......