What is the most efficient way of converting QStringList to QByteArray?
I have found many examples of similar conversions but never the one I needed or were just needlessly too complicated.
The code sanitize a string input and then convert it to QByteArray. I am struggling with the latter part.
void MainWindow::on_suicideButton_clicked()
{
QString input = ui->lineEdit->text();
try{
if(ui->lineEdit->text().contains("0x")||ui->lineEdit->text().contains(",")||ui->lineEdit->text().contains("-"))
{
input = input.replace("0x","");
if (input.contains(',')) input = input.replace(",", "");
// QString trim = input.trimmed();
// input = trim;//.split(',', ' ', '-');
QStringList inputArray = input.split('-');
QByteArray output = inputArray;
}
//printf("%s\n", input);
ui->lineEdit->setText(input);
}
catch (const std::bad_alloc &) {input = " ";}
}
QStringList inputArray = input.split('-'); is important (or at least I believe it to be so), as I would need to split the bytes into separate chunks in order to perform various operations on them.
Here is an example, in order for you to see what kind of operations I would like to do:
char MainWindow::checkSum(QByteArray &b)
{
char val = 0x00;
char i;
foreach (i, b)
{
val ^= i;
}
return val;
}
QArrayListin QT docs. - MRB