Help using QFile::open with a variable file path

  • 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;, QIODevice::ReadWrite);

    But that isn't working. Anyone have any ideas? Thanks!

  • I think you've got the code backwards: it should be
    @filename = ui->plainTextEdit->toPlainText();@

  • 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"

  • 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);;@

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.