3

I have the following code, with which I am attempting to write to a file. When it is called, the file is created in the directory and the for-loop is entered. The values for in QVector<int> program also exist and are visible with qDebug(). However, after I close the file and the window, I check the file on my computer and it is completely empty. I have checked all over StackOverflow and the Qt forums and have yet to find a solution.

    QString save_file = "C:/Users/MARVIN/Documents/Saddleback College/2015/Fall/CS3A/Semester Project/Emulator/hello.txt";

    QFile file(save_file);

    if(file.open(QFile::WriteOnly))
    {
        QTextStream out(&save_file);

        out << "hello" << endl;

        for(int i = 0; i < 100; i++)
        {
            out << program[i] << endl;
            qDebug() << program[i] << endl;
        }

        file.close();
        this->close();
    }
Jordan
  • 97
  • 2
  • 11

1 Answers1

4

Your issue:

QTextStream out(&save_file);

should be

QTextStream out(&file);
CJCombrink
  • 3,738
  • 1
  • 22
  • 38
  • ... Derp, haha. That was so obvious I am kind of embarrassed. I will accept your answer as soon as the time limit is up. – Jordan Nov 09 '15 at 06:24
  • @Jordan, Took me a few reruns and edits until I finally spotted it, so it is an easy mistake to make – CJCombrink Nov 09 '15 at 06:26