Qt Forum

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

    Byte data type, is it data type?

    General and Desktop
    3
    6
    18033
    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.
    • M
      m_pahlevanzadeh last edited by

      Dear all,

      I'm working on port a qt project to standard C++, every Qt data type that i use F2 shortcut has a typedef in qt header files, but didn't found byte data type? what's equivalent of byte in C ?

      1 Reply Last reply Reply Quote 0
      • U
        utcenter last edited by

        Byte is a char, 8bits worth of 256 values

        1 Reply Last reply Reply Quote 0
        • M
          m_pahlevanzadeh last edited by

          unsigned char or char ?

          1 Reply Last reply Reply Quote 0
          • U
            utcenter last edited by

            well, a byte is a byte, 8 bits, whether it will be encoded as a signed or unsigned number. You may have noticed QByteArray has utility functions to convert the byte array to unsigned short, int, long and long long.

            I don't recall there being a QByte typedef, so a byte is... a raw byte, merely a binary representation. A byte will yield a different value depending on whether you read is as a signed or unsigned char.

            1 Reply Last reply Reply Quote 0
            • M
              m_pahlevanzadeh last edited by

              So, it's an unsigned char, thank you.

              1 Reply Last reply Reply Quote 0
              • Jeroentjehome
                Jeroentjehome last edited by

                In the Windef.h file the BYTE is equal to the unsigned char. To make it cross-platform you might want to use the quint8 definition instead. Qt will make sure that it will always be 8 bits in the variable for all supported platforms.
                The BYTE will not be a big problem, but if you want to do the same for the int you might encounter strange things. A int could be a different size for any platform being 16, 32 or 64 bits wide!! Int is the default calculating variable of the platform. Using the quint16 or quint32 will make sure you always have enough bits to work with.
                When porting the Qt files to a different compiler you are able to include a "typedef.h" converting the quint8 definition etc to a standard C++ type.
                Greetz and hope this helps

                Greetz, Jeroen

                1 Reply Last reply Reply Quote 0
                • First post
                  Last post