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
Forum Update on Monday, May 27th 2025

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 28 Mar 2011, 16:36 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 28 Mar 2011, 16:41 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 28 Mar 2011, 16:45 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 28 Mar 2011, 17:36 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 28 Mar 2011, 20:27 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

            1/5

            28 Mar 2011, 16:36

            • Login

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