Unsolved sending data over serial port
-
hi....i want to send data over serial port to microcontroller....below is my code and im getting errors...so plz can anyone help
void MainWindow::on_btStatus_released() {
if ( m_serialPort->isOpen()) {
AddStatus("Comport open. ");
} else {
AddStatus("Comport not open. ");
}
QStringList text = "a";
m_serialPort->write(text.toStdString().c_str());}
Errors:
- error: C2440: 'initializing' : cannot convert from 'const char [2]' to 'QStringList'
Constructor for class 'QStringList' is declared 'explicit' - error: C2039: 'toStdString' : is not a member of 'QStringList'
3)error: C2228: left of '.c_str' must have class/struct/union
- error: C2440: 'initializing' : cannot convert from 'const char [2]' to 'QStringList'
-
- QStringList is a list of strings not a string. You should do QString text = ...
- When you fixed 1 then 2 will work
-
Hi,
Error 1: you are trying to assign a string in a QStringList, did you want QString ?
Error 2: Like written QStringList doesn't have such a method but QString does.
Error 3: Comes from error 2, you are trying to call a function over a result you don't have.Note that QSerialPort::write has an overload that takes a QByteArray so it's useless to do all these conversions
QByteArray data("a"); m_serialPort->write(data);
-
This post is deleted!