Qt 6.11 is out! See what's new in the release
blog
what is fprintf equivalent in qt ?
-
please provide suggestion to convert below c code into qt equivalent code
FILE *fp; int errnum,i=0; char ra[50],text[4]; fp = fopen(SOURCE_FILE,"r"); if( fp == NULL) { printf("the file is now opened.\n"); errnum = errno; fprintf(stderr, "Value of errno: %d\n", errno); perror("Error printed by perror"); fprintf(stderr, "Error opening file: %s\n", strerror( errnum )); } else { printf("file is now opened\n"); /* while( fgets(ra, 50, fp) != NULL) { printf("%s",ra); } */ fseek(fp, -543, SEEK_END); //fflush(ra); fgets ( ra, 50, fp ); printf("After SEEK_END to -505 :\n%s\n", ra); printf("sizeof(ra) %lu\n",sizeof(ra)); for(i;i<10;i++) { printf("%d %c \n",i,ra[i]); } text[0] = ra[1]; text[1] = ra[4]; text[2] = ra[7]; text[3] = '\0'; printf("text ------> %s\n",text); if( fclose(fp) == 0) { printf("data is read successfully \n"); printf("the file is now closed\n\n"); } printf("Data successfully read from file.c \n"); printf("the file is now closed.\n"); } -
please provide suggestion to convert below c code into qt equivalent code
FILE *fp; int errnum,i=0; char ra[50],text[4]; fp = fopen(SOURCE_FILE,"r"); if( fp == NULL) { printf("the file is now opened.\n"); errnum = errno; fprintf(stderr, "Value of errno: %d\n", errno); perror("Error printed by perror"); fprintf(stderr, "Error opening file: %s\n", strerror( errnum )); } else { printf("file is now opened\n"); /* while( fgets(ra, 50, fp) != NULL) { printf("%s",ra); } */ fseek(fp, -543, SEEK_END); //fflush(ra); fgets ( ra, 50, fp ); printf("After SEEK_END to -505 :\n%s\n", ra); printf("sizeof(ra) %lu\n",sizeof(ra)); for(i;i<10;i++) { printf("%d %c \n",i,ra[i]); } text[0] = ra[1]; text[1] = ra[4]; text[2] = ra[7]; text[3] = '\0'; printf("text ------> %s\n",text); if( fclose(fp) == 0) { printf("data is read successfully \n"); printf("the file is now closed\n\n"); } printf("Data successfully read from file.c \n"); printf("the file is now closed.\n"); }@Qt-embedded-developer said in what is fprintf equivalent in qt ?:
please provide suggestion to convert below c code into qt equivalent code
Take a look at
QFile,QTextStreamandQDataStream:
You could start here: https://doc.qt.io/qt-5/qfile.html#details