LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-15-2010, 09:17 PM   #1
vendtagain
Member
 
Registered: Sep 2009
Distribution: Slackware, Debian, Mac OS X, Zenwalk, Puppy, Gentoo
Posts: 199

Rep: Reputation: 32
storing numbers in QByteArray


I have a program that sends QByteArray datagrams over a udp socket. I would like to have 4 bytes of the datagram that contain a 32 bit integer. When saving numbers to the QByteArray, I have tried the static function number(int) and member function setNum(int), but they convert the integer to its decimal string representation and save that in the byte array. So if the number were 10, it takes 2 bytes, if it were 10,000,000 it takes 8 bytes. This wastes space, and makes it more difficult to get the number when it is packed with a few other pieces of data in the same datagram. Is there a standard way of doing this in Qt?
 
Old 12-16-2010, 09:12 AM   #2
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Check out QDataStream, I believe that is the standard way of doing it?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] find the total of numbers that are higher than x in a text file with numbers (using awk??) Mike_V Programming 12 11-24-2010 09:51 AM
Bash + Reading values(numbers) from a file and storing them into an array SuchANewb Linux - Newbie 5 11-04-2010 08:11 AM
[SOLVED] Reading numbers from text file and storing in array idaham Linux - General 3 05-27-2010 03:36 AM
convert int* to QByteArray Rhythm Programming 2 09-20-2008 12:28 AM
Storing numbers as 4 bytes in PHP. rblampain Programming 4 02-04-2006 10:06 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:07 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration