Code:

void MainWindow::on_pushButton_2_clicked() { QString QQ="\\d+(\\.\\d{0,}) \\d+(\\.\\d{0,}) \\d+(\\.\\d{0,})"; QRegExp rx(QQ); if (!checkRegExp(rx)) return; rx.setMinimal(true); ui->plainTextEdit_3->clear(); int pos = 0; QString QQQ=""; while ((pos=rx.indexIn(ui->plainTextEdit_2->toPlainText(),pos)) !=-1) { QQQ+=rx.cap(0)+"\n"; pos+=rx.matchedLength(); } ui->plainTextEdit_3->setPlainText(QQQ); QString str=QQQ; QStringList list= str.split(" ", QString::SkipEmptyParts); //Как в split() можно сделать разбиение сразу и по пробелу и по знаку новой строки? QList<float> fl; foreach (QString num, list) { fl.append(num.toFloat()); } } 

The thing is, I don’t understand exactly how this is done. I tried separately (from the control) to convert a string list to a list with floating point numbers (float). Everything worked fine there. Everything here does not work. Rather, it works, but not in the right way.

    1 answer 1

    You can use the regular schedule as a condition for a split:

     QRegExp rx("(\\ |\\,|\\.|\\:|\\t)"); //RegEx for ' ' or ',' or '.' or ':' or '\t' QStringList query = sometext.split(rx); 
    • And what regular will act for a space and a new line? QRegExp rx ("(\\ | \\ n)"); - this one? - Zenit Fan