Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set QTextStream in header?

Tags:

c++

qt

How do I set a new QTextStream in the header, like this

MainClass{
private:
    QTextStream out;
}

Then, in initialization set the file, so instead of

QTextStream out(&file), I would hope for something like

out.setFile(&file), but there's no .setFile in QTextStream

like image 333
JVE999 Avatar asked Dec 28 '25 10:12

JVE999


1 Answers

I found that QFile is an QIODevice, so QTextStream::setDevice(&QFile) will work.

Thus, now I have

MainClass{
private:
    QTextStream out;
    QFile file;
    void writetoBuffer();
}

void MainClass::writetoBuffer(){
    file.setFileName("bingbong.txt");
    out.setDevice(&file);
}
like image 67
JVE999 Avatar answered Dec 31 '25 02:12

JVE999