Hallo,
in my app the user has the possibility to add a station to a QListWidget. This works very well. After adding the station the list has to be updated. The problem, the QListWidget reads the stations and its frequency from a txt file.
So i need to sort the stations in the txt file not in the QListWidget, as I use the row index to tune to the station.
How can I sort the output before it is saved to the txt file?
The strings to campore look something like:
Jump,105600000
Station 1 93 MHz,93000000
man station@ 101.2MHz,101200000
Code:
ui->btn_rename->setVisible(true); float add_station_float = add_station.toFloat(); int multi = add_station_float * 1000000; if(!add_station.isEmpty()){ return; } return; } file_fm.resize(0); QStringList unsort_scan_fm; while(!in_file_fm.atEnd()){ QString outline = line; unsort_scan_fm.append(outline); } if(add_station.contains(",")){ add_station = add_station.replace(",", "."); } if(!add_station.contains(".")){ add_station = add_station.append(".0"); } //add new station at end of file unsort_scan_fm.append(outline); qDebug() << "before sort: :" << unsort_scan_fm; std::sort(unsort_scan_fm.begin(), unsort_scan_fm.end()); qDebug() << "after sort: :" << unsort_scan_fm; out << after_sort << "\n"; } file_fm.close(); out_tmp.flush(); out_tmp.close(); file_fm.remove(); out_tmp.rename(path_fm); ui->ls_fm->clear(); MainWindow::fill_list(); MainWindow::fm_list(); }
Debug before sort and after sort are the same:
Code:
after sort: : ("Jump,105600000", "Station 1 93 MHz,93000000", "Station 3 98.1 MHz,98100000", "Station 4 99.9 MHz,99900000", "Top40,94800000", "any station,107600000", "man station@ 100.2MHz,100200000", "man station@ 101.2MHz,101200000", "man station@ 101.3MHz,101300000", "man station@ 101.3MHz,101300000", "man station@ 104.6MHz,104600000", "man station@ 105.3MHz,105300000", "man station@ 105.4MHz,105400000", "man station@ 111.1MHz,111100000", "man station@ 96.8MHz,96800000", "man station@ 97.8MHz,97800000", "man station@ 99.9MHz,99900000", "zulu station,100700000")