How to access the same file in different scopes within a function
Hello All,
Please take a look at the below code. I posted a question earlier but had some changes after that.
Code:
FILE *filename1;
void MainWindow::on_checkBox_clicked()
{
if(ui->checkBox->isChecked())
{
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);
//
// 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.
Re: How to access the same file in different scopes within a function
Have you read the errors? You will likely find that they tell you why line 6 is not what you expected. It reads like a declaration of a function called file() that takes a QString argument and returns a QFile, and not a local variable of type QFile. Remove the stuff from ( to ) and see how much further you get. You then need to focus on lne 18.