Open Serial Port, handler from windows, error, the code works on standard C++
Hello, I'm trying to communicate a Qt program with a microcontroller board, (porting a program from C++). The original program works good on console, but moving the code from c++, to qt/c++ compile i get the next warning
WriteFile(handlerP,bufferPort,strlen(bufferPort),&bytesRW,NULL); (from the above line) warning: C4267: 'argument' : conversion from 'size_t' to 'DWORD', possible loss of data
and the next error
handlerP = CreateFile(serialPort, GENERIC_READ | GENERIC_WRITE,0,0,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,0); (from the avobe line) error: C2664: 'HANDLE CreateFileW(LPCWSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE)' : cannot convert argument 1 from 'char ' to 'LPCWSTR' Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
In theory must work.... ???
No idea, any help will be appreciated
thanks in advance, greetings.
Since you are using a serial port to communicate with your board. Why not use QSerialPort ?
As for your original problem, what type is serialPort ?
It is a virtual COM, for USB. I program for windows and i think that QSerial port musst appart compiled and linkend, right?
Greetings and thanks
If you are using Qt 5, no, it's in. You have to add
QT += serialportto your .pro file to use it.
the Windows API often has to version of a function.
One for use with C-like ANSI String (char) and one for wide chars like e.g. utf16 (UNICODE).
windows.hthe defines are mapped depending on the define for
Your error is because your project somewhere defines
CreateFilefunction maps to
This function expects the
FileNameparameter to be of type
wchar_t*, but your
serialPortis of type
Either you set your project to be non UNICODE, or you change your code to use wchar_t instead of char.
Bad practice would be to directly call
Thank you very much for your help!