Results 1 to 9 of 9

Thread: The best way to write compatible platform data format ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default The best way to write compatible platform data format ?

    Have I to rewrite all the code using types for this purpose (qint32, etc)
    Is there some macro or directive to to this work automatically ?
    Maybe I'm looking something impossible ?
    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: The best way to write compatible platform data format ?

    Hmm, QtCreator search and replace in all project files? Should do the trick.

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The best way to write compatible platform data format ?

    Thanks ly.
    It has a problem ? (change using qtcreator , i think ... ), all my simple vars used at for loops (in example) are going to changed ... I dont know if I need to do this.

    And I have a doubt : can I compare or use a standard and QT typedefs ? In example :
    Qt Code:
    1. int my_var_int;
    2. qint my_var_qint;
    3. if (my_var_int > my_var_qint) ....
    4. my_var_qint+=my_var_int;
    5. etc ...
    To copy to clipboard, switch view to plain text mode 
    And, what can I expect about the performance of my app ? That is, a windows app with int, double, etc are going to be faster than other that uses qint, qreal, etc. ?
    Maybe better to write a code to translate data from one platform to another instead of having the whole app multi-platform writed ? (I'm talking about binary data files or streams ).
    Thanks.

  4. #4
    Join Date
    Oct 2007
    Location
    Lake Forest, CA, USA
    Posts
    132
    Thanks
    10
    Thanked 27 Times in 22 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: The best way to write compatible platform data format ?

    Your program won't be faster, but you also won't get troubles with platform type differences. The best way to write cross-platform application is to have the same code for all platforms
    Oleg Shparber

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The best way to write compatible platform data format ?

    Yes, but I'm talking about types...
    Thanks

  6. #6
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: The best way to write compatible platform data format ?

    Quote Originally Posted by tonnot View Post
    Thanks ly.
    And, what can I expect about the performance of my app ? That is, a windows app with int, double, etc are going to be faster than other that uses qint, qreal, etc. ?
    Nothing. All Qt types are C typedefs. So for the compiler there is no difference whether you write qint32 or signed int because it is defined qint32.

  7. #7
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The best way to write compatible platform data format ?

    All Qt types are C typedefs. So for the compiler there is no difference whether you write qint32 or signed int because it is defined qint32.
    So.... Have I or not to write my code using qt typedefs ?
    And a last question, the endianness is not fixed using qt typedefs isn't it ?
    Thanks

  8. #8
    Join Date
    Nov 2010
    Posts
    315
    Thanked 53 Times in 51 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: The best way to write compatible platform data format ?

    Last edited by MarekR22; 15th November 2011 at 13:11.

  9. #9
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: The best way to write compatible platform data format ?

    For example : on smaller processors an int - might - be 16 bits instead of 32 bits, and then your programs won't work if you really need the 32 bits. And on a 64-bit processor, your program - might - behave differently if you rely on the 'overflow' of your numbers (e.g. If you expect that if you add 1 to 0xFFFFFFFF that you get 0x00000000).

    But in many cases the C types have the same size for different platforms. I say 'many', not 'most' or 'all', so if you really want to be safe, then you should use qint etc.

    Endianess is determined by the processor architecture. It is transparent to you (unless you start packing values in binary arrays, for which you should use QDatastream).

    Regards,
    Marc

  10. The following user says thank you to marcvanriet for this useful post:

    tonnot (23rd November 2011)

Similar Threads

  1. Qt to Matlab (mat format) export data to Matlab .mat format -v4
    By windsword in forum Qt-based Software
    Replies: 4
    Last Post: 26th February 2013, 20:01
  2. Replies: 1
    Last Post: 14th January 2011, 11:57
  3. Replies: 6
    Last Post: 7th December 2010, 12:32
  4. Opendocument format read/write *.odt
    By patrik08 in forum Qt Programming
    Replies: 7
    Last Post: 17th September 2008, 00:48
  5. Using Qt to write Cross Platform Library
    By ball in forum Qt Programming
    Replies: 2
    Last Post: 3rd April 2006, 09:58

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.