Results 1 to 12 of 12

Thread: How to convert QByteArray to char*?

  1. #1
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default How to convert QByteArray to char*?

    How to convert QByteArray to char*? I want to copy the contents of the file from HTTP to be read
    Am using
    Qt Code:
    1. http.read(Char* Data,len)
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to convert QByteArray to char*?

    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Jun 2011
    Posts
    8
    Thanked 3 Times in 3 Posts
    Qt products
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: How to convert QByteArray to char*?

    copy from QByteArray
    use QByteArray::data() and QByteArray::count();

    copy to QByteArray
    use QByteArray::append

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to convert QByteArray to char*?

    Have you read the QByteArray docs? Here's a hint: Look for methods where "char *" is the return value.

    Of course, "char *" is not the same as "Char *", but I have assumed that is a typo.

  5. #5
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert QByteArray to char*?

    But this Read function always reads the file from the beginning. I want to read certain number of characters at a time. How to do that?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to convert QByteArray to char*?

    Quote Originally Posted by Gokulnathvc View Post
    But this Read function always reads the file from the beginning.
    Then don't use it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert QByteArray to char*?

    Quote Originally Posted by wysota View Post
    Then don't use it.
    Its not proper on your side.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to convert QByteArray to char*?

    What do you mean? You had said some function didn't do what you wanted so I told you to use something else that does what you want.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Mar 2011
    Location
    Coimbatore,TamilNadu,India
    Posts
    382
    Thanks
    10
    Thanked 13 Times in 12 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to convert QByteArray to char*?

    I just enquired whether it if possible to read the file for particular length each time using this QHttp read method. I have tried and it is always reading from the beginning. I don't know whether its my mistake that i have used this wrongly. Help me in fixing this issue.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to convert QByteArray to char*?

    First of all you didn't say anything about QHttp. Second of all since the data comes from the network, we're not talking about a file but rather a stream of bytes. And as with all streams, the data is not seekable -- you need to read it from the start. If you want bytes 10-15 then read 16 bytes and discard first ten.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to convert QByteArray to char*?

    Apart from not mentioning QHttp, which you have been told several times is obsolete and should not be used in new code, you failed to mention that you wanted to access parts of a network stream, parts of an in-memory buffer, what you had tried, why you think that didn't work, etc. I seriously don't understand how you expected your question:
    How to convert QByteArray to char*?
    to lead to anything resembling the answer you expected.

    As wysota says, network streams are sequential. You can read an discard bits you don't want: this will work everywhere. If the upstream server supports range retrieval then you can request only the bytes you want: this has nothing to do with either Qt or obtaining a char * to a QByteArray's data.

  12. #12
    Join Date
    Sep 2009
    Location
    Turkey / istanbul
    Posts
    1
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: How to convert QByteArray to char*?

    hi

    it is working...

    void RxParser(char *Data, int DataLen)
    {
    ..
    }

    void Clients::TCPsocketready()
    {
    QByteArray Data = socket->readAll();
    RxParser(Data.data(),Data.length());
    }

Similar Threads

  1. How to convert int to char?
    By Bong.Da.City in forum Newbie
    Replies: 12
    Last Post: 9th January 2015, 19:45
  2. how to convert an int to QByteArray
    By babu198649 in forum Qt Programming
    Replies: 12
    Last Post: 19th September 2014, 09:47
  3. How to convert unsigned char[] to char *?
    By Gokulnathvc in forum Newbie
    Replies: 2
    Last Post: 29th April 2011, 08:58
  4. QByteArray can not support unsigned char?
    By olosie in forum Newbie
    Replies: 2
    Last Post: 31st July 2010, 10:02
  5. QByteArray char to int
    By pdoria in forum Qt Programming
    Replies: 1
    Last Post: 15th July 2009, 17:36

Tags for this Thread

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.