You have to do it the other way around. First, you create the QFile and open it. Then you create the QTextStream object and give it the QFile object as the first argument.