Hello,
I have a LineEdit, i want to retrieve the string and pass it to winapi.
WinApi input type is LPWSTR, and LineEdit type is QString. May kindly advise me on how to change from QString to LPWSTR.
Thank you
Hello,
I have a LineEdit, i want to retrieve the string and pass it to winapi.
WinApi input type is LPWSTR, and LineEdit type is QString. May kindly advise me on how to change from QString to LPWSTR.
Thank you
Use QString::toStdWString:
Qt Code:
// not tested QString string = ...; std::wstring wstr = string.toStdWString(); LPWSTR ptr = wstr.c_str();To copy to clipboard, switch view to plain text mode
Please click one of the Quick Reply icons in the posts above to activate Quick Reply.
Sorry:
It is giving me the error "invalid conversion from 'const wchar_t*' to 'WCHAR*'"
Thank you
Added after 23 minutes:
I solved it this way :
QString passQt;
wchar_t* pass;
pass = (wchar_t*) malloc (sizeof(wchar_t)*passQt.length()+1);
passValQt.toWCharArray(pass);
pass[passQt.length()]=0; // Null terminate the string
It gives the correct result. What do you think about the solution ?
Thank you
Last edited by nackasha; 3rd August 2011 at 19:31.
KalEl (9th May 2017)
Ok, so try with LPCWSTR (C means const) instead LPWSTR in conversion. If the winapi method requires pointer to wide string (not pointer to const wide string), you will need to allocate the memory for wstring yourself and copy the wstring.c_str() content ( you should not modify the pointer returned by c_str() ).
Or maybe you can use QString::toWCharArray with self-allocated wchar_t array.
---
edit:
Thats what I meant in second part of this post, but maybe this way:
Qt Code:
int length = passValQt.toWCharArray(pass); pass[length]=0; // Null terminate the stringTo copy to clipboard, switch view to plain text mode
nackasha (3rd August 2011)
Bookmarks