Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Help using QFile::open with a variable file path

Help using QFile::open with a variable file path

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 10.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wonopon12
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris H
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • W Offline
        W Offline
        wonopon12
        wrote on last edited by
        #3

        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"

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris H
          wrote on last edited by
          #4

          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 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved