PDA

View Full Version : appending QByteArray with variable.



jjbabu
18th October 2007, 06:12
hi to all,
for my application,i am taking the data into QByteArray,after taking the all the data ia m writing this to port.
my problem is the data i am taking,some are constants,some are variables.
for example initially i have taken like this,
QByteArray xyz(": 3 ");
now i want to append the QByteArray with some variable,which is the value of spinbox in my GUI.
int X=ui.spinBox->value();

how can i append the "xyz" with 'X' value?

thanks in advance

kernel_panic
18th October 2007, 06:24
xyz += QByteArray::number(X);

jjbabu
18th October 2007, 08:04
after appending i collect all the data into the QByteArray xyz;

xyz contains(: 3 0 0 0.............etc)
now i have taken the size of QByteArray xyz;
int n=xyz.size();

now i want to insert the variable 'n' betweenthe value'3'[index4]and value'0'[index6]
how can i insert the variable 'n' in my required position?

please help me.

kernel_panic
18th October 2007, 08:24
generally i would use a

QList<QByteArray> byteArrayList;
for this.
it would be much easier.
if you know where to insert value n, you can use

xyz.insert(5, QByteArray::number(n));