Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    File size

    General and Desktop
    4
    5
    5755
    Loading More Posts
    • 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
      luca72 last edited by

      @
      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 Reply Quote 0
      • F
        florent.revelut last edited by

        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 Reply Quote 0
        • F
          florent.revelut last edited by

          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 Reply Quote 0
          • V
            vinb last edited by

            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 Reply Quote 0
            • G
              goetz last edited by

              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 Reply Quote 0
              • First post
                Last post