Results 1 to 10 of 10

Thread: How to resolve qbyteA[5] = qbyteB?

  1. #1
    Join Date
    Feb 2007
    Posts
    47
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy How to resolve qbyteA[5] = qbyteB?

    Hi,every one!Can you tell me how to resolve the following problem?
    Qt Code:
    1. QByteArray qbyteA,qbyteB;
    2. qbyteA.resize(9);
    3. ........
    4. qbyteA[5] = qbyteB;//error: QByteArray:: operator QNoImplicitBoolCast() const' is private
    To copy to clipboard, switch view to plain text mode 
    I don't know why,please anyone if you know tell me,thank you very much!
    Last edited by jpn; 11th January 2008 at 16:58. Reason: missing [code] tags

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to resolve qbyteA[5] = qbyteB?

    What are you trying to achieve ?
    qByteA[5] = qByteB ; Here you are trying to assign the byte array qByteB to sixth character of qByteA (qByteA[5]) . How can this be possible ??
    You can assign character to character. If qByteA was an array of pointers to QByteArray, then that statement would have worked.

    Hence its giving error that it cannot find any suitable conversion for the statement.

  3. #3
    Join Date
    Feb 2007
    Posts
    47
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy Re: How to resolve qbyteA[5] = qbyteB?

    Thank you for your kind help,but I have already try for many ways,such as
    Qt Code:
    1. QByteArray byteA[9],byteB; or QByteArray *byteA,byteB;
    2. byteA[0] = 0x23;//error: invalid conversion from `int' to `const char*'
    To copy to clipboard, switch view to plain text mode 
    I want to give
    Qt Code:
    1. byteA[i] = 0xxx,byteA[j] = byteB
    To copy to clipboard, switch view to plain text mode 
    ,how I can do? Please!
    Last edited by jpn; 11th January 2008 at 16:59. Reason: missing [code] tags

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to resolve qbyteA[5] = qbyteB?

    You can assign hex values to QByteArray,,, like qByteA[5] = 0xA2 - Hex format.
    or u can use QByteArray::fromHex.

    If you are trying to assign some part of qByteB to qByteA then trim qByteB first and use the assignement operator.

  5. #5
    Join Date
    Feb 2007
    Posts
    47
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to resolve qbyteA[5] = qbyteB?

    Why?But there no member QByteArray::fromHex.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to resolve qbyteA[5] = qbyteB?

    Quote Originally Posted by hiuao View Post
    QByteArray byteA[9],byteB; or QByteArray *byteA,byteB;
    byteA[0] = 0x23;//error: invalid conversion from `int' to `const char*'
    Here byteA is an array of QByteArrays, so byteA[0] is QByteArray.

    Quote Originally Posted by hiuao View Post
    I want to give byteA[i] = 0xxx,byteA[j] = byteB,how I can do?
    Make sure the types match:
    Qt Code:
    1. QByteArray byteA, byteB;
    2. ...
    3. byteA[0] = 0x11;
    4. byteA[1] = byteB[2];
    To copy to clipboard, switch view to plain text mode 

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to resolve qbyteA[5] = qbyteB?

    Why?But there no member QByteArray::fromHex.
    Why ? did u click on the link ? Its a static member function.

  8. #8
    Join Date
    Feb 2007
    Posts
    47
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to resolve qbyteA[5] = qbyteB?

    Sorry to replay so late.I think your version maybe QT4.3,but mine is QT4.2.2,so there is no fromHex in my version.I want to do as the following,please tell me if I am right,Thank you very much!
    Qt Code:
    1. QByteArray bytA[3],bytB;
    2. bytA[0] = "0x34";
    3. bytA[1] = bytB;
    4. bytA[2] = QByteArray( ( 2*(bytA[0].toLong())& 0x000000ff )<<8 );
    To copy to clipboard, switch view to plain text mode 
    I want to know if the function use "QByteArray::toLong(),& ,<<" is right.
    Last edited by jpn; 16th January 2008 at 11:44. Reason: missing [code] tags

  9. #9
    Join Date
    Feb 2007
    Posts
    47
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to resolve qbyteA[5] = qbyteB?

    Quote Originally Posted by jacek View Post
    Here byteA is an array of QByteArrays, so byteA[0] is QByteArray.

    Make sure the types match:
    Qt Code:
    1. QByteArray byteA, byteB;
    2. ...
    3. byteA[0] = 0x11;
    4. byteA[1] = byteB[2];
    To copy to clipboard, switch view to plain text mode 
    I don't think its proper,excuse me to say so.If byteB only have one byte,how can it do?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to resolve qbyteA[5] = qbyteB?

    Quote Originally Posted by hiuao View Post
    If byteB only have one byte,how can it do?
    Even if it contains a single byte, still its type is QByteArray. You have to extract that single byte in order to make the assignment:
    Qt Code:
    1. byteA[2] = byteB[0];
    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.