Help with Qt Invalid conversion
-
Error created in below code
a-invalid conversion from 'unsigned char' to 'const char*'
b-no matching function for call to 'QSerialPort::write(QString)@
void MainWindow::SendContrast()
{static const char Contrast0[]={0x08,0x11,0x01,0x00,0x00,'\0'}; static const char Contrast1[]={0x04,0x12,0x84,'\0'}; serial->write(Contrast0); serial->write(ui->ContrastCombo->currentText()); //a serial->write(ModBusCRC(Contrast0,sizeof(Contrast0))); //b because ModBusCRC return a const char serial->write(Contrast1); serial->write(ModBusCRC(Contrast1,sizeof(Contrast1)));
}
@
-
Hi,
currentText() returns a QString where write wants a QByteArray so you have to convert it using e.g. toLatin1().
Where exactly does the other error happen ?
-
thanks, i edit the question.
Understood QLatin1 better now
http://qt-project.org/doc/qt-4.8/qlatin1string.html -
Then something like:
@
char crc = ModBusCRC(Contrast0,sizeof(Contrast0));
serial->write(&crc, 1);
@should work.