Page 2 of 7 FirstFirst 1234 ... LastLast
Results 21 to 40 of 121

Thread: dynamicCall and QByteArray - strange characters

  1. #21
    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

    No, I meant the structure you would be getting if you were calling the method directly using WinAPI's COM API. I just can't say it more clearly. Or just dump the byte array to the console in ascii, see what is there and try to guess its stucture.

  2. #22
    Join Date
    Apr 2010
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: dynamicCall and QByteArray - strange characters

    Quote Originally Posted by wysota View Post
    No, I meant the structure you would be getting if you were calling the method directly using WinAPI's COM API. I just can't say it more clearly. Or just dump the byte array to the console in ascii, see what is there and try to guess its stucture.
    If I can try to put it a bit more clearly:

    Your dynamic call returns a QByteArray with 441 elements right? So all those return types (CardID, OverWrite, idxDesignation and all those) you listed should be contained in those 441 elements.
    What wysota means by structure is how those 441 elements are divided to produce the return types ie. CardID is a string of size 10, OverWrite a byte(or bit) etc... If you have that structure you can try to cast the QByteArray to that structure. Otherwise you'll need to determine the structure as wysota mentioned - by dumping to ascii and trying to figure out the type of each return type.

  3. #23
    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

    Quote Originally Posted by franco.amato View Post
    Hi, I don't understand a thing: I don't have to use the new operator to instantiate the objects?
    That depends on the lifetime you expect the object (m_treeView in my example) to have. On the stack is fine for a short lifespan limited by scope, on the heap would be more typical. The code generated by dumpcpp connects to COM control at the time the wrapper object is constructed and doesn't care how the object came to be.

    You have had success with dumpcpp creating some wrappers. The generated classes should manage marshalling COM response into qt and/or C++ structures for you make for more direct access (adjust names as needed):
    Qt Code:
    1. #include "generated_header.h"
    2. ...
    3. terminalLib::oTerminal *comObject;
    4.  
    5. comObject = new terminalLib::oTerminal(this);
    6. QVariant result = oTerminal->GetUserData(QString("some card id thingy"));
    7. delete comObject;
    To copy to clipboard, switch view to plain text mode 
    If you dig around in the generated H and CPP file you might find a definition of "ArrayList" (or it may be intended to be an opaque blob although this seems unlikely). You may also find references to a Windows help file that matches the type library.

    Could you post (attach) the generated header file?

  4. #24
    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

    If the QVariant returned is of type QByteArray then the COM return was a SAFEARRAY(BYTE) according to the QAxBase documentation.
    You might find this useful:
    http://www.roblocher.com/whitepapers/oletypes.aspx
    http://msdn.microsoft.com/en-us/libr...ROT.13%29.aspx

  5. #25
    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
    That depends on the lifetime you expect the object (m_treeView in my example) to have. On the stack is fine for a short lifespan limited by scope, on the heap would be more typical. The code generated by dumpcpp connects to COM control at the time the wrapper object is constructed and doesn't care how the object came to be.

    You have had success with dumpcpp creating some wrappers. The generated classes should manage marshalling COM response into qt and/or C++ structures for you make for more direct access (adjust names as needed):
    Qt Code:
    1. #include "generated_header.h"
    2. ...
    3. terminalLib::oTerminal *comObject;
    4.  
    5. comObject = new terminalLib::oTerminal(this);
    6. QVariant result = oTerminal->GetUserData(QString("some card id thingy"));
    7. delete comObject;
    To copy to clipboard, switch view to plain text mode 
    If you dig around in the generated H and CPP file you might find a definition of "ArrayList" (or it may be intended to be an opaque blob although this seems unlikely). You may also find references to a Windows help file that matches the type library.

    Could you post (attach) the generated header file?
    Dear Chris,
    for sure. Tomorrow I'll post the .h file.

    Regards

  6. #26
    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 zAAm View Post
    If I can try to put it a bit more clearly:

    Your dynamic call returns a QByteArray with 441 elements right? So all those return types (CardID, OverWrite, idxDesignation and all those) you listed should be contained in those 441 elements.
    What wysota means by structure is how those 441 elements are divided to produce the return types ie. CardID is a string of size 10, OverWrite a byte(or bit) etc... If you have that structure you can try to cast the QByteArray to that structure. Otherwise you'll need to determine the structure as wysota mentioned - by dumping to ascii and trying to figure out the type of each return type.
    If I well understood I have to first create such structure with struct and then cast the returned value to such structure? Or I'm wrong?
    Can I have some pseudo-code?

  7. #27
    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
    If I well understood I have to first create such structure with struct and then cast the returned value to such structure?
    Did you try entering "ArrayList C++" in your favourite search engine and reading what pops up?

  8. #28
    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
    Did you try entering "ArrayList C++" in your favourite search engine and reading what pops up?
    The arrayList is not the problem. The problem is the return value that's QByteArray
    Franco Amato

  9. #29
    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
    Could you post (attach) the generated header file?
    I tried to send the files you asked for but the forum says they are bigger than the limit.
    If you have a mail address I can send them to you.

    Regards

  10. #30
    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

    Compress them. Then you will be able to attach them to your post. And only send the relevant file (.h).

  11. #31
    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
    Compress them. Then you will be able to attach them to your post. And only send the relevant file (.h).
    Ok Wysota thank you.
    I compressed PallyCom.h in PallyCom.zip ( 8K )

    Regards
    Attached Files Attached Files

  12. #32
    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
    Compress them. Then you will be able to attach them to your post. And only send the relevant file (.h).
    Wysota I saw some data calling the routine in a C# console application and I had to do a conversion byte to ascii to see something.
    I think if for that that I can not see nothing in Qt. How can I convert the bytearray in ascii?
    I also saw that the stream of data contains lots of '\0' and for that maybe I can not see well all characters.

    Best
    Last edited by franco.amato; 21st April 2010 at 20:31.

  13. #33
    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
    How can I convert the bytearray in ascii?
    What did you already try to do it?

  14. #34
    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
    What did you already try to do it?
    Hi,
    first I have know how to access to every byte contained in the bytearray and discover how Qt manage the '\0' as in the
    returned stream I have lots of such character
    Franco Amato

  15. #35
    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
    Hi,
    first I have know how to access to every byte contained in the bytearray and discover how Qt manage the '\0' as in the
    returned stream I have lots of such character
    Then open the documentation of QByteArray and read it. I can tell you that Qt doesn't "manage" null bytes in any way. They are bytes like any other.

  16. #36
    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
    Then open the documentation of QByteArray and read it.
    This is was I already did many times

    I can tell you that Qt doesn't "manage" null bytes in any way. They are bytes like any other.
    This is the result of the routine call in a cmd line app written in C#:

    "I??\0\0xml;q=0.Franco\0\0\0\0\0\0\0\0\0Amato\0\0 \0\0\0\0\0\0\0\0\0\0\0\0AAAAAAAAAAAAAAA=0\0\n \n0987654321`E?\"UF ??\fCQ????O\"D ?\v2??(E??\n2F?D?\fH1\b\vH???\nIae?.???(?`>?/?p<?;M???????:????\"8??`:?!???PQ?\r??`'?`2 ??Q)\n??#3?????#34????\"34????\"34O???\"34O? ??\"#3D???#4D???#4D???#4D???34D???\"3DD? ??#DDE???4DTE???4UUEo??EUUUo???VffUo???ffff?? ?wwff????wwvg?\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0 \0\0\0\0\0\0\0\0\0"
    You can see many '\0' but why debuggind with visual studio my Qt app I can not see the same string that's should contained in the QByteArray? And also I really don't understand which characteres are these:     ??

    I hope you can help me
    Franco Amato

  17. #37
    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

    You still seem to be expecting a nice human readable string when what you are being passed is a binary data structure. The docs for the COM server say it returns an ArrayList (a .Net/C# data type of some sort) but this has to be translated to something that can be sent through the COM interface, which must remain language agnostic. The QAxBase docs imply this structure is a SAFEARRAY(BYTE). I'd hazard a guess it's a single dimensional array of VT_VARIANT entries.

    In your C++ Qt application you receive a QByteArray. Use QByteArray::toHex() to dump the first 24 or 32 bytes. Then sit and try to marry the bytes to the SAFEARRAY structures described here;
    http://msdn.microsoft.com/en-us/library/aa913233.aspx
    Qt Code:
    1. typedef struct FARSTRUCT tagSAFEARRAY {
    2. unsigned short cDims; // two bytes
    3. unsigned short fFeatures; // two bytes
    4. unsigned short cbElements; //two bytes
    5. unsigned short cLocks; // two bytes
    6. unsigned long handle; // four bytes
    7. void HUGEP* pvData; // four bytes
    8. SAFEARRAYBOUND rgsabound[1]; // structure below repeated if more than one dimension in array
    9. } SAFEARRAY;
    10.  
    11. typedef struct tagSAFEARRAYBOUND {
    12. unsigned long cElements; // four bytes
    13. long lLbound; // four bytes
    14. } SAFEARRAYBOUND;
    To copy to clipboard, switch view to plain text mode 
    Does the number of dimensions make sense? Do the array bounds make sense? If so, read here:
    http://msdn.microsoft.com/en-us/library/ms221145.aspx
    You might want to use your favourite search engine to look for a C++ wrapper for SAFEARRAYs.

  18. #38
    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
    This is was I already did many times
    Then do it again and again until you find something you consider useful for writing a routine for dumping the byte array in ascii (or hex or whatever you find important). I can already tell you there is no method in QByteArray that will do the task for you - you have to come up with a proper algorithm yourself. Otherwise you won't learn anything and next time you will again ask someone for help instead of trying to solve the problem on your own first.

  19. #39
    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
    Then do it again and again until you find something you consider useful for writing a routine for dumping the byte array in ascii (or hex or whatever you find important). I can already tell you there is no method in QByteArray that will do the task for you - you have to come up with a proper algorithm yourself. Otherwise you won't learn anything and next time you will again ask someone for help instead of trying to solve the problem on your own first.
    My problem is not convert byte to ascii,
    my problem is understand why QByteArray doesn't contain the data as It should
    Franco Amato

  20. #40
    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
    my problem is understand why QByteArray doesn't contain the data as It should
    How do you know it doesn't contain the data?

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.