How to save any string in text file in Qt ?
-
If I fetched data in (QString str ) str then I have to copy all the data which is in str to Copy.txt(Text File) file with file location. How Can I do it ?
-
If I fetched data in (QString str ) str then I have to copy all the data which is in str to Copy.txt(Text File) file with file location. How Can I do it ?
@Pappu-Kumar-Keshari Please start here:
- https://doc.qt.io/qt-6/qfile.html
- https://doc.qt.io/qt-6/qtextstream.html - here you can even find example code for your use case
-
If you are attempting to store your string data in a file, then you can probably look at this example:
void save_to_file(QString filePath, QString data) { if(filePath.isEmpty()) { qDebug() << "File path is empty!" return; } QFile fileObject(filePath); if(!fileObject.open(QIODevice::WriteOnly)) { qDebug() << "Error! could not open file." return; } QTextStream stream(&fileObject); stream << data; fileObject.close(); }
Hope this helps.