Using Multi-Byte in place of Unicode
I have some code that was written for windows. One of the parameters requires multi-byte instead of unicode. In Visual Studio 2008 I can change that in Project->Class Properties->Configuration Set. Is it possible to do this in Qt 4? The project I am working on right now requires Multi-Byte input vs Unicode, but I cannot seem to change/convert it to work right.
Thanks
Re: Using Multi-Byte in place of Unicode
Qt uses Unicode internally, I doubt you can change that. But converting to wchar* (or std::wstring) should be possible (QString::toStdWString()).
Re: Using Multi-Byte in place of Unicode
Thanks for the speedy reply sir!
Buuuuut it didn't work as easy as I had hoped .
Here is the code that is breaking.
Code:
char adjust_device[16];
sprintf(adjust_device, "\\\\.\\%s", device);
HComm = CreateFile(adjust_device, GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (HComm == INVALID_HANDLE_VALUE) {
return -1;
}
I tried to do this:
Code:
sprintf(QString::toStdWString(adjust_device
),
"\\\\.\\%s", device
);
HComm = CreateFile(adjust_device, GENERIC_READ | GENERIC_WRITE, 0,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
and I get the following error: no matching function call toQString::toStdWstring(char[16])
Any ideas?
Re: Using Multi-Byte in place of Unicode
It's not a static method, that's one thing. The other is that it will convert the string to std::wstring, just as the name of the method says and not to a char*. The device name probably contains ascii characters only anyway, so you can probably do this:
Code:
QString device
= "<something goes here">;
QString adjustDeviceStr
= "\\\\.\\"+device;
HComm = CreateFile(ba.constData(), ...);
Re: Using Multi-Byte in place of Unicode
There's two versions of CreateFile:
CreateFileA takes a ASCII parameters (char *)
CreateFileW takes Unicode parameters (wchar *)
Typically, if you have Unicode defined, CreateFileW is aliases to CreateFile, else CreateFileA is aliased to CreateFile.
You can still use either by using the proper names:
Code:
CreateFileW(foo.utf16(), ...)
Code:
char foo[] = "\\\\.\\COM1";
CreateFileA(foo, ...)
Re: Using Multi-Byte in place of Unicode
Thanks a bunch. I used CreateFileA and it seems to be working.
I'm new to Qt so I have a noob question to ask. How can I display a long in a Line Edit? I tried this
Code:
ui->txtAhead->setText(number);
but it just inserts blank spaces. I used debugging mode to check what lmsDist[540] was and it was an actual number (6530, 87, etc). What am I doing wrong?
Thanks again with your help.
Re: Using Multi-Byte in place of Unicode
Re: Using Multi-Byte in place of Unicode
Works like a champ. Thanks a million!