Results 1 to 4 of 4

Thread: appending QByteArray with variable.

  1. #1
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default appending QByteArray with variable.

    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

  2. #2
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: appending QByteArray with variable.

    xyz += QByteArray::number(X);

  3. The following user says thank you to kernel_panic for this useful post:

    jjbabu (18th October 2007)

  4. #3
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: appending QByteArray with variable.

    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.

  5. #4
    Join Date
    Jan 2007
    Posts
    177
    Thanks
    8
    Thanked 10 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: appending QByteArray with variable.

    generally i would use a
    Qt Code:
    1. QList<QByteArray> byteArrayList;
    To copy to clipboard, switch view to plain text mode 
    for this.
    it would be much easier.
    if you know where to insert value n, you can use
    Qt Code:
    1. xyz.insert(5, QByteArray::number(n));
    To copy to clipboard, switch view to plain text mode 

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.