0

Basically I have a line-edit box which take the user input such as comma separated values and on clicking the push-button it write all the values of line-edit box to a text file. But same feature I want to achieve through combobox. So whenever one of the item selected from combobox it should write the contents of line-edit box to a text file.

The code I have used so far to implement using push-button

void MainWindow::writefile()
{
    QString str = ui->lineEdit->text();
    QString filename = "data.txt";
    QFile file(filename);
    if(file.open(QIODevice::WriteOnly|QIODevice::Text))
    {
    QTextStream out(&file);
    out<<str<<endl;
    file.close();
    }
}
void MainWindow::on_pushButton_clicked()
{
    writefile();
} 
Chinmoy
  • 493
  • 1
  • 5
  • 16

1 Answers1

0

Sounds like all you need to do is implement ItemListener and make itemStateChanged do exactly what your actionPerformed does.