Can I initizialize a QFile and assign a value in a second time? I tried in this way
...
QFile file;
...
if (i == 0) file = QFile("foo.txt");
else file = QFile("bar.txt");
...
But Qt Creator rises this error: "'QFile& QFile::operator=(const QFile&)' is private within this content"
Can you help me?
QFile
is a QObject
, and those are non-copyable and non-assignable. What you're looking for is the setFileName
method:
QFile file;
...
file.setFileName(i == 0 ? "foo.txt" : "bar.txt");
...
You could also have
QFile file(i == 0 ? "foo.txt" : "bar.txt");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With