So my lineedit is named "data", and the pushButton is named "sendData", here is the code I have:
void MainWindow::on_sendData_clicked()
{
int size = list1.size();
char senddata[size];
for (int i=0; i <= size; i++){
bool ok;
senddata[i]=ran.toInt(&ok,16);
}
serial->write(senddata,sizeof(senddata));
}
void MainWindow::on_sendData_clicked()
{
QString input = ui->data->text();
QStringList list1 = input.split(",");
int size = list1.size();
char senddata[size];
for (int i=0; i <= size; i++){
QString ran = list1 [i];
bool ok;
senddata[i]=ran.toInt(&ok,16);
}
serial->write(senddata,sizeof(senddata));
}
To copy to clipboard, switch view to plain text mode
I thought it would work okay, but somehow I can't initialize the char array "senddata" without an actual size, do you have any fix for that? Thank you.
Bookmarks