BSTR to QString Conversion
How can i convert BSTR to QString. Please Give a example.
Re: BSTR to QString Conversion
This probably works:
Don't forget to free the BSTR, else you will get memory leaks!
Re: BSTR to QString Conversion
Quote:
Originally Posted by
_Stefan
This probably works:
Don't forget to free the BSTR, else you will get memory leaks!
This is not working give me some other solution.
BSTR containing the starting base address of a string. I need to convert into QString.
Re: BSTR to QString Conversion
Can you elaborate on the exact problem?
Show some code, debug messages?
Re: BSTR to QString Conversion
Quote:
Originally Posted by
_Stefan
Can you elaborate on the exact problem?
Show some code, debug messages?
BSTR codesetID;
if(pGetID_Outron->GetCodesetID(&codesetID, &codesetLength) == S_OK)
{
}
CodesetID containg the starting address.
Now we need to get in QString, to which BSTR is pointing to.
Re: BSTR to QString Conversion
But what happens when you use the suggested code?
Re: BSTR to QString Conversion
Quote:
Originally Posted by
_Stefan
This probably works:
It is my understanding that this will not work as the first 4 bytes of a BSTR contain the length of the string, so you would have to compensate for this. Maybe QString convertedBSTR((QChar*) &bstr[4], wcslen(bstr)); ?
Re: BSTR to QString Conversion
Re: BSTR to QString Conversion
Try:
std::wstring intermediateString(myBSTR, SysStringLen(myBSTR);
QString finalString = QString::fromStdWString(intermediateString);
-K
Re: BSTR to QString Conversion
No need to use std:
QString qstr((QChar*)bstr, ::SysStringLen(bstr));