[Qt-interest] File Size human-readable ?

Omar AKHAM crtx.omar at gmail.com
Mon Aug 30 16:11:28 CEST 2010


Ok, thanks,

I derivate the QFileInfo class and add a function QString size_humain();

here is the function, maybe can interest some one :

    QString QFileInfoHumanSize::size_human()
    {
         float num = this->size();
         QStringList list;
         list << "KB" << "MB" << "GB" << "TB";

         QStringListIterator i(list);
         QString unit("bytes");

         while(num >= 1024.0 && i.hasNext())
          {
             unit = i.next();
             num /= 1024.0;
         }
         return QString().setNum(num,'f',2)+" "+unit;
    }

Regards,
Omar

Le 30/08/2010 12:51, Atlant Schmidt a écrit :
> Omar:
>
>    Do you mean a method that will convert an arbitrary
>    integer to QStrings that contain strings such as:
>
>      o "12 Bytes"
>      o "1.3 kBytes"
>      o "27.6 Mbytes"
>      o "78.27 GBytes"
>
>    and so forth?
>
>    If so, I don't know of a Qt method to do this (others
>    may, of course) but it's very easy to do this in plain
>    old C(++) using an if-else_if chain. And in writing it
>    yourself, you get to decide on the points where you
>    switch the formatting for the various "sizes", how
>    much precision to display at each step, and so on.
>
>                           Atlant
>
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Omar AKHAM
> Sent: Friday, August 27, 2010 14:13 PM
> To: qt-interest at trolltech.com
> Subject: [Qt-interest] File Size human-readable ?
>
> Hi all,
>
> I'm looking for a Qt function to have a file size in human readable
> format (size is returned by QFileInfo).
>
> Thanks,
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> This e-mail and the information, including any attachments, it contains are intended to be a confidential communication only to the person or entity to whom it is addressed and may contain information that is privileged. If the reader of this message is not the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please immediately notify the sender and destroy the original message.
>
> Thank you.
>
> Please consider the environment before printing this email.
>    

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100830/8e3a41c7/attachment.html 


More information about the Qt-interest-old mailing list