Help using QFile::open with a variable file path
-
wrote on 15 Dec 2011, 22:42 last edited by
Hey, I just can't seem to get QFile::open() working with a variable file path.
I'm trying to do :
@
QString filename;
Qfile file;ui->plainTextEdit->toPlainText() = filename;
file.open(filename, QIODevice::ReadWrite);
@But that isn't working. Anyone have any ideas? Thanks!
-
wrote on 15 Dec 2011, 23:02 last edited by
I think you've got the code backwards: it should be
@filename = ui->plainTextEdit->toPlainText();@ -
wrote on 16 Dec 2011, 00:04 last edited by
thanks for the reply =D it wasn't the solution however. sorry about that, i should have elaborated more on the error
"bool QFile::open(FILE*, QIODevice::OpenMode) : cannot convert parameter 1 from QString to FILE"
-
wrote on 16 Dec 2011, 01:43 last edited by
Oh, I see: the open() method of Qfile doesn't work the way you are thinking. You either need to pass the filename to the constructor, e.g.
@Qfile file (filename)@
or you need to set the name and then call open(), e.g.
@Qfile file;
file.setFileName (filename);
file.open(QIODevice::ReadWrite);@
1/4