Solved How to read the files in XML
-
@aha_1980 said in I Got this as a error: declaration of 'QString filename' shadows a parameter:
if you want to open it for reading?
yes how to open and read and write
-
@sankarapandiyan And have you the needed access rights?
-
-
@sankarapandiyan Then your code should work!
What is the output of:
file /home/newuser/Desktop/xmlfileoutput/filenamemw.xml/setting1xmlpage2.xml/setting2xmlpage3.xml/setting3xmlpage4.xml
in a terminal?
-
@aha_1980
i am not able to read
error:Could not open the file for reading
Could not open the file for reading
Could not open the file for reading
Could not open the file for reading -
@aha_1980
My problem is that i put four file names into one path
what to do ?
i think this is the problem -
You should first open only
/home/newuser/Desktop/xmlfileoutput/filenamemw.xml
and read it.After that finished, you can read the second file and so on.
Ok?
-
@aha_1980
QFile file("/home/newuser/Desktop/xmlfileoutput/filenamemw.xml");
yes now it opens , But unable to read it
this the output,
Starting /home/newuser/Desktop/designtest-build-desktop-Qt_4_8_1_in_PATH__System__Release/designtest...
opened
opened
opened
openedQFile file("/home/newuser/Desktop/xmlfileoutput/filenamemw.xml/setting1xmlpage2.xml");
if i add the second file and run the code ,the output is like this ,
Starting /home/newuser/Desktop/designtest-build-desktop-Qt_4_8_1_in_PATH__System__Release/designtest...
Could not open the file for reading
Could not open the file for reading
Could not open the file for reading
Could not open the file for reading -
This is not how QFile works...
QFile expects from you to give a path to the constructor.
Therefore if you have 4 files you need 4 QFiles (Or 1 file and change the path with the "setFileName" method of QFile after finished one reading).QFile file1("/home/newuser/Desktop/xmlfileoutput/filenamemw.xml");
QFile file2("/home/newuser/Desktop/xmlfileoutput/setting1xmlpage2.xml");
(not sure if this is the correct path as I can't look into your file Manager)
...
or simply after you have finished reading file1
file1.setFileName("/home/newuser/Desktop/xmlfileoutput/setting1xmlpage2.xml");I suppose, you function header should look therefore more like this:
void copyFiles(const QStringList& sources, const QString& destination);
You first open your file with destionation as the path for writing, as this is the file where you copy the 4 other xml files in.
Next you loop over the QStringLists with a for each loop. In it you open a file with the path you get form QStringList. Read it line for line and write the content line for line in the destination file.
You call could look like this
int main() { QStringList pathes = {"/home/newuser/Desktop/xmlfileoutput/filenamemw.xml", "/home/newuser/Desktop/xmlfileoutput/setting1xmlpage2.xml"}; copyFiles(pathes, "/path/to/your/destination/file"); }
If you get something like "could not open" first test if you give the right path to the file by using the command aha_1980 recommended you:
$ file /path/to/your/file -
By the way, depending on your file manager, you usually can click right on the file and there will be something in the menu like "properties" if you click on it, you will see the path to the file or to the folder the file is in it.
In last case you need to add /yourFileName to get the complete path. -
@Leon_2001 ok i wil try Thanks a lot