QString fn = QFileDialog::getOpenFileName(this, tr("Open")); QFile file(fn); file.open(QFile::ReadOnly); QString line; QTextStream in(&file); QStringList string; while (!in.atEnd()) { line = in.readLine(); QString ch = ";"; int l = 0; for (int i=0; i<line.length(); i++) { if (line[i]==ch[0]) { string<<line.mid(l,i-l); ui->listWidget->addItem(line.mid(l,i-l)); l=i+1; } } ui->comboBox->addItem(string[0]); qDebug()<<string; string.clear(); }
QString fn = QFileDialog::getOpenFileName(this, tr("Open")); QFile file(fn); if(file.open(QFile::ReadOnly)) { QString line; QTextStream in(&file); QStringList strings; while (!in.atEnd()) { line = in.readLine(); for(int i=0, l = 0; i < line.length(); i++) { if(line[i] == QChar(';')) { QString string = line.mid(l,i-l); if(!strings.contains(string)) { strings.append(string); } ui->listWidget->addItem(string); l=i+1; } } } ui->comboBox->addItems(strings); }
QString fn = QFileDialog::getOpenFileName(this, tr("Open")); QFile file(fn); if(file.open(QFile::ReadOnly)) { QTextStream in(&file); QStringList strings; while (!in.atEnd()) { QString line = in.readLine(); int separator = line.indexOf(';'); QString comboBoxString = (separator != -1 ? line.left(separator) : line); if(!strings.contains(comboBoxString)) { strings.append(comboBoxString); }; for(int i=0, l = 0; i < line.length(); i++) { if(line[i] == QChar()) { QString string = line.mid(l,i-l); ui->listWidget->addItem(string); l=i+1; } } } ui->comboBox->addItems(strings); }