Relative path to save file
-
wrote on 1 Nov 2019, 15:25 last edited by
Hi All,
I need to save an xml. I'm getting the file name as:
QString filename = QFileDialog::getSaveFileName(this, "Save Xml", ui->lineEdit_3->text(), "Xml files (*.xml)");
File need to saved here in the location (build folder of the project):
C:\Users\L23454\Code_Refer\DataManagement\build-SQLDataManagement-Desktop_Qt_5_12_0_MSVC2015_64bit-Debug\Patient Data
And, my project is here:
C:\Users\L23454\Code_Refer\DataManagement
How do I mention the path where the file needs to be saved?
Thanks in advance -
Hi All,
I need to save an xml. I'm getting the file name as:
QString filename = QFileDialog::getSaveFileName(this, "Save Xml", ui->lineEdit_3->text(), "Xml files (*.xml)");
File need to saved here in the location (build folder of the project):
C:\Users\L23454\Code_Refer\DataManagement\build-SQLDataManagement-Desktop_Qt_5_12_0_MSVC2015_64bit-Debug\Patient Data
And, my project is here:
C:\Users\L23454\Code_Refer\DataManagement
How do I mention the path where the file needs to be saved?
Thanks in advancewrote on 1 Nov 2019, 15:28 last edited by@russjohn834 hi
-
wrote on 1 Nov 2019, 15:49 last edited by
Thank you @LeLev
A few doubts: i need to save data one step back from:QCoreApplication::applicationDirPath()
so I did this:QDir dir(QCoreApplication::applicationDirPath()); QString location = dir.relativeFilePath("./Patient Data/");
Is that correct?
Then how do I mention this location here with the file name:
QString filename = QFileDialog::getSaveFileName(this, "Save Xml", ui->lineEdit_3->text(), "Xml files (*.xml)");
-
Thank you @LeLev
A few doubts: i need to save data one step back from:QCoreApplication::applicationDirPath()
so I did this:QDir dir(QCoreApplication::applicationDirPath()); QString location = dir.relativeFilePath("./Patient Data/");
Is that correct?
Then how do I mention this location here with the file name:
QString filename = QFileDialog::getSaveFileName(this, "Save Xml", ui->lineEdit_3->text(), "Xml files (*.xml)");
wrote on 1 Nov 2019, 16:15 last edited by ODБOï 11 Jan 2019, 17:05https://doc.qt.io/qt-5/qdir.html#relativeFilePath
@russjohn834 said in Relative path to save file:
Is that correct?
you can check it
QDir dir(QCoreApplication::applicationDirPath()); QString location = dir.relativeFilePath("../PatientData/"); qDebug()<<location; QFile file(location + "/test.txt"); QTextStream out(&file); if(!file.open(QIODevice::WriteOnly | QIODevice::Text)){ return; } out << "test" ; file.close();
-
wrote on 1 Nov 2019, 16:42 last edited by
@LeLev . Thank you.
I need to save file to a location, say for ex. (
QCoreApplication::applicationDirPath()
) with a file name (ui->lineEdit_3->text()
).The file should be saved to the location upon clicking the button.
But, I dont know why if I do this, the file file dialogue window popping in
QString filename = QFileDialog::getSaveFileName(this, "Save Xml", location.append("/"+ui->lineEdit_3->text()), "Xml files (*.xml)"); QFile file(filename);
Any thoughts!?
-
@LeLev . Thank you.
I need to save file to a location, say for ex. (
QCoreApplication::applicationDirPath()
) with a file name (ui->lineEdit_3->text()
).The file should be saved to the location upon clicking the button.
But, I dont know why if I do this, the file file dialogue window popping in
QString filename = QFileDialog::getSaveFileName(this, "Save Xml", location.append("/"+ui->lineEdit_3->text()), "Xml files (*.xml)"); QFile file(filename);
Any thoughts!?
wrote on 1 Nov 2019, 17:53 last edited by@russjohn834
You callQFileDialog::getSaveFileName()
in order to present the user with the file dialog to choose where to save, with your location as the default. If you already know what path you want to save to, like in your case, you don't want to call this, just save to the file without asking the user further. -
Hi
You just need to open a file and save the data.
Something like:QString filename =ui->lineEdit_3->text();
QString path=QCoreApplication::applicationDirPath()+"/"+filename +".xml";
QFile file(path);
QTextStream out(&file);
// try to open
if(!file.open(QIODevice::WriteOnly | QIODevice::Text)){
return;
}
// save the sdata
out << "test" ;
file.close(); -
wrote on 4 Nov 2019, 10:45 last edited by russjohn834 11 Apr 2019, 10:46
3/8