View Full Version : How to write in a QFile
gorka_sm
4th May 2011, 21:33
Hello I want to write a text in a QFile , for example /home/hello.txt.
Does anybody know any example of code for doing it ?
Thanks
Gorka
Lykurg
4th May 2011, 21:52
Yes, I do. And also the documentation. Search it!
tinysoft
5th May 2011, 13:08
here .. try this one:
void MainWindow::on_pushButton_clicked()
{
QString file = "D:/hello.txt";
QFile outputFile(file);
outputFile.open(QIODevice::WriteOnly);
QString str = "text inside file";
if(!outputFile.isOpen())
{
//alert that file did not open
}
QTextStream outStream(&outputFile);
outStream << str;
outputFile.close();
//open text file to user
QDesktopServices::openUrl(QUrl(tr("file:///D:/hello.txt")));
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.