I am writing a QT widgets application that includes serial communication with an Arduino. I found a good header and cpp file on GitHub that makes communicating with an Arduino MUCH easier than it would be with QSerialPort.
However one difficulty that this presents is that the port name must be given as a char array in the format "\\.\COM1" for example. So I'm trying to add those backslashes before the COM port name, with this code:
QString currentPort = "\\\\.\\" + QString(ui->serialPortDropdown->itemText(index));
portName = currentPort.toLocal8Bit().data();
After initialising the array with this at the top of my cpp file:
char *portName;
After adding a few qDebug()s here and there, the QString is being set to how it should be, "\\\\.\\COM1"
for example. But the char array is returning as "\\.\COM1"
. So the backslashes are cancelling other backslashes.
How do I overcome this?
Thanks in advance for any help :)