Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Opening a file to read and write to
Forum Updated to NodeBB v4.3 + New Features

Opening a file to read and write to

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 1.6k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    Doomberries
    wrote on last edited by
    #1

    Hi everyone,
    So I'm trying to have my application be able to open a .txt file and read off a few lines of numbers. I have the txt file in the directory with all the .cpp and .h files but it won't open. I've added it to the project and so it is included in the .pro file. Any ideas? I can't figure out if its a necessitas issue or I'm just missing something super simple.

    @ifstream theFile;
    theFile.open("highscores.txt", ios::in);
    @

    I've tried different forms of the path too, w/ w/o "/" or the full path. Nothing has worked.
    Thanks in advance.
    -Doomberries

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tucnak
      wrote on last edited by
      #2

      Hi, ~Doomberries!

      Welcome to Qt Developer Network!

      It's better to use "QFile":http://qt-project.org/doc/qt-4.8/qfile.html class to work with files in Qt. Learn about it on the net. Just gugl it.
      Code sample with QFile:
      @
      QFile file("highscores.txt");
      if(!file.open(QIODevice::ReadWrite)) {
      // impossible to open
      } else {
      // here you can read from file
      }
      @

      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