Page 5 of 7 FirstFirst ... 34567 LastLast
Results 81 to 100 of 121

Thread: dynamicCall and QByteArray - strange characters

  1. #81
    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: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    You found the value 1234567890 in the first 4 bytes??? Really?
    Sure.

    If yes please help me to extract and show it as I'm becoming crazy.
    Take a calculator (preferably one that understands hex) and calculate it yourself from the hex dump you provided

    Or simply ask Google - 0x499602d2 in decimal.
    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.


  2. #82
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    Sure.


    Take a calculator (preferably one that understands hex) and calculate it yourself from the hex dump you provided

    Or simply ask Google - 0x499602d2 in decimal.
    I tried these code:
    Qt Code:
    1. QByteArray ba = m_axobj->dynamicCall("GetUserData(QString)", myCardId ).toByteArray();
    2.  
    3. int cardIdBE = 0;
    4. memcpy( &cardIdBE, ba, sizeof(int) );
    5. int cardIdLE = qFromBigEndian(cardIdBE);
    6. qDebug() << cardIdLE; //1234567890
    To copy to clipboard, switch view to plain text mode 

    And it returns the correct value,
    thank you
    Franco Amato

  3. #83
    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: dynamicCall and QByteArray - strange characters

    You should use qint32 (or quint32 if the number is unsigned) and not int.
    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.


  4. #84
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    You should use qint32 (or quint32 if the number is unsigned) and not int.
    Wysota how can I do to convert from bigendian some bytes of the qbytearray?
    For example I would convert from bigendian the bytes from ba[14] to ba[28] ( 15 bytes ).

    I did this
    Qt Code:
    1. char* name = new char[15];
    2. memcpy( name, &ba[14], sizeof(char)*15); //I copy 15 bytes of ba to name
    3. char* name_converted = new char[15];
    4. name_converted = qFromBigEndian(name);
    To copy to clipboard, switch view to plain text mode 

    now I would convert from bigendian the content of name to display the name.
    but the qFromBigEndian doesn't return as value a char[] so I can not display correct a name
    Franco Amato

  5. #85
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    Wysota how can I do to convert from bigendian some bytes of the qbytearray?
    For example I would convert from bigendian the bytes from ba[14] to ba[28] ( 15 bytes ).

    I did this
    Qt Code:
    1. char* name = new char[15];
    2. memcpy( name, &ba[14], sizeof(char)*15); //I copy 15 bytes of ba to name
    3. char* name_converted = new char[15];
    4. name_converted = qFromBigEndian(name);
    To copy to clipboard, switch view to plain text mode 

    now I would convert from bigendian the content of name to display the name.
    but the qFromBigEndian doesn't return as value a char[] so I can not display correct a name
    qFromBigEndian() is a template function and returns type given in template call.

    But... Can you name a type which has a 15 bytes?? I don't know such type... they rather have 2^n bytes, so what type do you want to get?
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  6. #86
    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: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    Wysota how can I do to convert from bigendian some bytes of the qbytearray?
    For example I would convert from bigendian the bytes from ba[14] to ba[28] ( 15 bytes ).

    I did this
    Qt Code:
    1. char* name = new char[15];
    2. memcpy( name, &ba[14], sizeof(char)*15); //I copy 15 bytes of ba to name
    3. char* name_converted = new char[15];
    4. name_converted = qFromBigEndian(name);
    To copy to clipboard, switch view to plain text mode 

    now I would convert from bigendian the content of name to display the name.
    but the qFromBigEndian doesn't return as value a char[] so I can not display correct a name
    I think you should first learn what "big-endian" and "little-endian" actually mean and whether they have any application in this context.
    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. #87
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    I think you should first learn what "big-endian" and "little-endian" actually mean and whether they have any application in this context.
    I know what [big-little]endian is, the bit alignment, depending of cpus.
    In my case I have a processor that align in bigendian and to show the data in my pc I have to convert in littleendian
    Franco Amato

  8. #88
    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: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    I know what [big-little]endian is,
    I don't think you do.

    the bit alignment, depending of cpus.
    It has nothing to do with neither "bit" nor "alignment".

    In my case I have a processor that align in bigendian and to show the data in my pc I have to convert in littleendian
    Please, do me a favour and read about it again, because you are wrong.
    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. #89
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    I don't think you do.


    It has nothing to do with neither "bit" nor "alignment"..
    In computing, endianness is the ordering of individually addressable sub-units (words, bytes, or even bits) within a longer data word stored in external memory. From http://en.wikipedia.org/wiki/Endianness ( It has nothing to do with bit ?? alignement or ordering for me is the same )

    Please, do me a favour and read about it again, because you are wrong.
    Maybe my english is not perfect and I'm not able to well explain but I know what big or little endian is
    Franco Amato

  10. #90
    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: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    alignement or ordering for me is the same
    Well, maybe it's the same for you but it's not the same. And please go past what is written in wikipedia. That's a source of "information" not a source of information.

    Maybe my english is not perfect and I'm not able to well explain but I know what big or little endian is
    Good, let's see that. Let's assume the following data has been written on a big-endian machine:
    Qt Code:
    1. quint32 x = 0x12345678;
    2. const char *str = "abcd"; // remember about implicit '\0' at the end of the string
    To copy to clipboard, switch view to plain text mode 
    Could you please tell me how a little-endian machine would interpret values of both variables (assuming it was somehow loaded directly into its memory core)? Just please don't write a program to do it, just use your mind, all the needed data is here.

    Edit: sorry, one thing that may be important is missing here - do it assuming both machines are 32bit architectures.
    Last edited by wysota; 25th April 2010 at 22:23.
    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. #91
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    Well, maybe it's the same for you but it's not the same. And please go past what is written in wikipedia. That's a source of "information" not a source of information.


    Good, let's see that. Let's assume the following data has been written on a big-endian machine:
    Qt Code:
    1. quint32 x = 0x12345678;
    2. const char *str = "abcd"; // remember about implicit '\0' at the end of the string
    To copy to clipboard, switch view to plain text mode 
    Could you please tell me how a little-endian machine would interpret values of both variables (assuming it was somehow loaded directly into its memory core)? Just please don't write a program to do it, just use your mind, all the needed data is here.

    Edit: sorry, one thing that may be important is missing here - do it assuming both machines are 32bit architectures.
    0x78563412 in first case and
    "dcba" in second case
    Franco Amato

  12. #92
    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: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    0x78563412 in first case and
    "dcba" in second case
    Are you sure? You can still change something if you want. Take your time...
    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.


  13. #93
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    Are you sure? You can still change something if you want. Take your time...
    No I don't change. It should be so
    Franco Amato

  14. #94
    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: dynamicCall and QByteArray - strange characters

    Ok, if you say so... You are wrong, the proper answer is:

    0x78563412 or 0x56781234 in first case (both forms are correct little-endian encodings, even your wikipedia article says that when you bother to read the whole article and not only the first few lines) and "abcd" in second case.

    Character strings are opaque for the processor, it doesn't interpret them in any way so there is no point in manipulating the order of bytes in them hence they are always stored as "big-endian". This is very logical, because each character occupies exactly one byte so there is nothing to reverse there and subsequent characters occupy subsequent bytes in memory. Otherwise it wouldn't be possible to iterate character strings and this is where "alignment" kicks in:
    Qt Code:
    1. quint32 array[4];
    2. quint32 *aPtr = array;
    3. quint32 *aPtr2 = array+1;
    4. int diff1 = (int)(aPtr2) - (int)(aPtr);
    5. char str[4];
    6. char *sPtr =str;
    7. char *sPtr2 = str+1;
    8. int diff2 = (int)(aPtr2) - (int)(aPtr);
    To copy to clipboard, switch view to plain text mode 
    diff1 will equal 4 and diff2 will equal 1. ints are word-aligned, chars are byte-aligned.

    Now that you have all that knowledge, go back to your problem with converting the blob from big-endian and solve it. Think whether this opaque byte array is more related to an array of ints or to an array of chars.

    Just a side note - you wouldn't have to do all that if you did what I asked you to a few dozens of posts ago - dump the byte array in ascii format to the console to see what's inside it. I just suspect you don't know how to do that and are afraid to admit it because otherwise you would have done it long ago.

    Edit: By the way, even assuming little-endian architectures were storing strings as you described it, your answer would still be incorrect. I told you to look out for the implicit \0 character that is at the end of the string. You answer should be "dcba"+3bytes of garbage+'\0' or '\0'+"dcba".
    Last edited by wysota; 25th April 2010 at 23:35.
    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.


  15. #95
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    Ok, if you say so... You are wrong, the proper answer is:

    0x78563412 or 0x56781234 in first case (both forms are correct little-endian encodings, even your wikipedia article says that when you bother to read the whole article and not only the first few lines) and "abcd" in second case.

    Character strings are opaque for the processor, it doesn't interpret them in any way so there is no point in manipulating the order of bytes in them hence they are always stored as "big-endian". This is very logical, because each character occupies exactly one byte so there is nothing to reverse there and subsequent characters occupy subsequent bytes in memory. Otherwise it wouldn't be possible to iterate character strings and this is where "alignment" kicks in:
    Qt Code:
    1. quint32 array[4];
    2. quint32 *aPtr = array;
    3. quint32 *aPtr2 = array+1;
    4. int diff1 = (int)(aPtr2) - (int)(aPtr);
    5. char str[4];
    6. char *sPtr =str;
    7. char *sPtr2 = str+1;
    8. int diff2 = (int)(aPtr2) - (int)(aPtr);
    To copy to clipboard, switch view to plain text mode 
    diff1 will equal 4 and diff2 will equal 1. ints are word-aligned, chars are byte-aligned.

    Now that you have all that knowledge, go back to your problem with converting the blob from big-endian and solve it. Think whether this opaque byte array is more related to an array of ints or to an array of chars.

    Just a side note - you wouldn't have to do all that if you did what I asked you to a few dozens of posts ago - dump the byte array in ascii format to the console to see what's inside it. I just suspect you don't know how to do that and are afraid to admit it because otherwise you would have done it long ago.

    char a;
    iterate over all size() of the byte array
    a = ba[i];
    qDebug() << int(a)

    I'm not afraid, I'm out of office and I can not access to my code/data
    Franco Amato

  16. #96
    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: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by franco.amato View Post
    char a;
    iterate over all size() of the byte array
    a = ba[i];
    qDebug() << int(a)
    Hmm... what is this supposed to do? It seems it will dump the array as decimal numbers which doesn't say anything new if you already have it dumped as hex.

    I'm not afraid, I'm out of office and I can not access to my code/data
    I'm not in your office, I don't have access to your code nor to your data but I can make an ascii dump of your byte array at any moment based on what was written in this thread so stop having excuses to everything and start thinking. We're repeating those late-night discussions each day and you are still at ground zero.
    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.


  17. #97
    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: dynamicCall and QByteArray - strange characters

    Franco. Have a look at your ASCII dump of the block of data. You are interested in 15 chars starting at a certain offset. What order are the characters in?
    Qt Code:
    1. char* name = new char[15];
    2. memcpy( name, &ba[14], sizeof(char)*15); //I copy 15 bytes of ba to name
    3. char* name_converted = new char[15];
    4. name_converted = qFromBigEndian(name);
    To copy to clipboard, switch view to plain text mode 
    What's in name after line 2? Why do you want to change the order of the bytes in this string?

  18. #98
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by faldżip View Post
    qFromBigEndian() is a template function and returns type given in template call.

    But... Can you name a type which has a 15 bytes?? I don't know such type... they rather have 2^n bytes, so what type do you want to get?
    I only would convert an undefined number of bytes
    Franco Amato

  19. #99
    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: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by ChrisW67 View Post
    What's in name after line 2? Why do you want to change the order of the bytes in this string?
    He doesn't even have to copy the data, C semantics of character strings is very useful here.

    Qt Code:
    1. QByteArray ba = ...
    2. const char *dat = ba.constData();
    3. const char *name = dat+14; // or strdup(dat+14) if one wants to have an own copy
    4. printf("NAME: %s\n", name);
    To copy to clipboard, switch view to plain text mode 
    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.


  20. #100
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by ChrisW67 View Post
    Franco. Have a look at your ASCII dump of the block of data. You are interested in 15 chars starting at a certain offset. What order are the characters in?
    Qt Code:
    1. char* name = new char[15];
    2. memcpy( name, &ba[14], sizeof(char)*15); //I copy 15 bytes of ba to name
    3. char* name_converted = new char[15];
    4. name_converted = qFromBigEndian(name);
    To copy to clipboard, switch view to plain text mode 
    What's in name after line 2? Why do you want to change the order of the bytes in this string?
    Dear Chris,
    my stream of bytes come from a fingerprint reader that order bytes using bigendian order.
    So I read data and to process them I have to first convert to little endian to understand it.
    Wysota told that character strings doen't matter so I have to change the order of the rest of my stream
    Franco Amato

Similar Threads

  1. Replies: 0
    Last Post: 16th April 2010, 23:21
  2. Regarding qbytearray
    By mohanakrishnan in forum Qt Programming
    Replies: 7
    Last Post: 19th November 2009, 13:38
  3. Replies: 9
    Last Post: 25th July 2009, 13:27
  4. Replies: 1
    Last Post: 28th May 2008, 16:52
  5. QByteArray in Qt3
    By joseph in forum Qt Programming
    Replies: 1
    Last Post: 6th September 2007, 06:16

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.