rookee
10th December 2015, 20:13
Hello All,
Please take a look at the below code. I posted a question earlier but had some changes after that.
FILE *filename1;
void MainWindow::on_checkBox_clicked()
{
QFile file(QString fname);//LINE1
if(ui->checkBox->isChecked())
{
filename = QFileDialog::getSaveFileName(...);//LINE2
if(!filename.isEmpty())
{
if(QFile::exists(filename)){
//Append 2 empty lines and append data(some data)
}else { // I want to access the filename from LINE2 create a file with name entered by user and append some data
file(filename);
file.open(QIODevice::Append);
//
// Data to be appended
//
}
}
}
}
Can someone please help me understand how to access filename from LINE2 and do some stuff on that file in a different location within the function on_checkBox_clicked(). I'm trying to declare a file in LINE1 and use it to perform different checks, this is throwing some errors. Please explain the syntax for using the filename in a different scope/sub-scope(or what ever they call it) within the same function with above example. And if I want to access the same file in different function of my project, how can I access it. Thanks in advance.
Please take a look at the below code. I posted a question earlier but had some changes after that.
FILE *filename1;
void MainWindow::on_checkBox_clicked()
{
QFile file(QString fname);//LINE1
if(ui->checkBox->isChecked())
{
filename = QFileDialog::getSaveFileName(...);//LINE2
if(!filename.isEmpty())
{
if(QFile::exists(filename)){
//Append 2 empty lines and append data(some data)
}else { // I want to access the filename from LINE2 create a file with name entered by user and append some data
file(filename);
file.open(QIODevice::Append);
//
// Data to be appended
//
}
}
}
}
Can someone please help me understand how to access filename from LINE2 and do some stuff on that file in a different location within the function on_checkBox_clicked(). I'm trying to declare a file in LINE1 and use it to perform different checks, this is throwing some errors. Please explain the syntax for using the filename in a different scope/sub-scope(or what ever they call it) within the same function with above example. And if I want to access the same file in different function of my project, how can I access it. Thanks in advance.