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. File size

File size

Scheduled Pinned Locked Moved General and Desktop
5 Posts 4 Posters 6.0k 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.
  • L Offline
    L Offline
    luca72
    wrote on last edited by
    #1

    @
    QFile mio_f(nome);
    if (!mio_f.open(QIODevice::ReadOnly)){
    size = mio_f.size();
    }
    @
    Why i get the size = 0

    Thanks Luca

    1 Reply Last reply
    0
    • F Offline
      F Offline
      florent.revelut
      wrote on last edited by
      #2

      You should use '@' balises around your code to make it more readble:
      @
      QFile mio_f(nome);
      if (!mio_f.open(QIODevice::ReadOnly)){
      size = mio_f.size();
      }
      @

      1 Reply Last reply
      0
      • F Offline
        F Offline
        florent.revelut
        wrote on last edited by
        #3

        Qfile::open returns "true" if successful

        In your code, your variable size is assignated only if open failed. If it succeeded, your variable isn't touched, it then keeps its previous value (might be 0 depending on compiler and your definition).
        Note that documentation doesn't state what size should return on an erronous file, but 0 seems good ;-)

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

          try this:
          @
          QFile mio_f(nome);
          if (!mio_f.open(QIODevice::ReadOnly))
          return; //when file doesnt open.
          size = mio_f.size(); //when file does open.

          @
          where 'nome' is a var with the path to file in it || nome is path to file

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            The coding style discussion has been moved to "this thread":http://developer.qt.nokia.com/forums/viewthread/4777/.

            http://www.catb.org/~esr/faqs/smart-questions.html

            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