Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using QFile
Qt 6.11 is out! See what's new in the release blog

Using QFile

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 577 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    viniltc
    wrote on last edited by
    #1

    Hi all,

    I have the following bit of code written in C:

            FILE *f=fopen(config_file_name, "rb");
            if(!f)
            {
                perror(config_file_name);
                printf("Could not open file '%s'\n", config_file_name);
                return;
            }
            size_t len=0;
            while(!feof(f))
            {
                len+=fread(config+len, 1, MAX_CONFIG_FILE_LENGTH-len, f); // to read bytes from file
            }
            fclose(f);
            if(len)
            {
                send_long_register((nv_config?STIM_LONG_REG_NV_STIM_CONFIG_FILE:STIM_LONG_REG_STIM_CONFIG_FILE), len, (uint8_t*)config); // send the content to another function
            }
            else
            {
                printf("Could not read any bytes from file.\n");
            }
    

    How can I do the same operations using QFile??

    Thank you :)

    JonBJ 1 Reply Last reply
    0
    • V viniltc

      Hi all,

      I have the following bit of code written in C:

              FILE *f=fopen(config_file_name, "rb");
              if(!f)
              {
                  perror(config_file_name);
                  printf("Could not open file '%s'\n", config_file_name);
                  return;
              }
              size_t len=0;
              while(!feof(f))
              {
                  len+=fread(config+len, 1, MAX_CONFIG_FILE_LENGTH-len, f); // to read bytes from file
              }
              fclose(f);
              if(len)
              {
                  send_long_register((nv_config?STIM_LONG_REG_NV_STIM_CONFIG_FILE:STIM_LONG_REG_STIM_CONFIG_FILE), len, (uint8_t*)config); // send the content to another function
              }
              else
              {
                  printf("Could not read any bytes from file.\n");
              }
      

      How can I do the same operations using QFile??

      Thank you :)

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @viniltc
      Unless you expect someone to spell out each equivalent QFile method corresponding to each of your FILE ones, have you read through https://doc.qt.io/qt-5/qfile.html ? The corresponding methods are really pretty obviously named....

      1 Reply Last reply
      6
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #3
        QFile f(config_file_name);
        if(!f.open(QFile::ReadOnly))
        qDebug() << "Could not open file " << config_file_name;
        QByteArray config = f.readAll();
        send_long_register(config);
        

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        4
        • V Offline
          V Offline
          viniltc
          wrote on last edited by
          #4

          Thanks a lot @VRonin That's exactly what I was looking for

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved