Page 2 of 2 FirstFirst 12
Results 21 to 37 of 37

Thread: QFile::copy copies only 3kb

  1. #21
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile::copy copies only 3kb

    There is no magic wand here. Don't expect a single call to exist that does all the work for you. You need to design an algorithm that will fulfill all your requirements. You know what the problem is so you need to find a way to resolve it. You need an approach that will 1) detect new files in the directory and the time they appeared there, 2) detect when a new file is completely copied into the directory, 3) copy the file to its proper place. Once you do that you need to implement the algorithm in code. And don't expect the solution to be a single linear block of code. It's likely you'll have to implement a class that does that using signals and slots.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  2. The following user says thank you to wysota for this useful post:

    camol (12th April 2011)

  3. #22
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::copy copies only 3kb

    I've tried sth like this:

    Qt Code:
    1. void DServer::newFiles_()
    2. {
    3. this->inputWatcher->blockSignals(true);
    4. fileTimer->start();
    5. }
    6.  
    7. void DServer::newFilesTimer_()
    8. {
    9. output = "";
    10. ps.start("du -sk /home/camol/INPUT_DICOM");
    11. }
    12.  
    13. void DServer::cmdExec_data_available()
    14. {
    15. output += ps.readAllStandardOutput() + "\n";
    16. }
    17.  
    18. void DServer::cmdExec_finish(int pl)
    19. {
    20. QTextStream(stdout) << "INPUT FOLDER SIZE: " << output.remove("/home/camol/INPUT_DICOM")<<endl;
    21. ps.close();
    22. QTextStream(stdout) << "INPUT FOLDER SIZE int: " << output.toInt()<<endl;
    23. if(output.toInt() > lastInput)
    24. this->lastInput = output.toInt();
    25. else
    26. {
    27. QTextStream(stdout) << "mam wszystko: " << lastInput<<endl;
    28. inputFiles = getPaths(QDir::homePath() + "/INPUT_DICOM");
    29. this->fileTimer->stop();
    30. emit this->_copy();
    31. }
    32. }
    To copy to clipboard, switch view to plain text mode 

    ps is a QProcess object and it works it constantly updates the size of the folder during copying the files but still copying the files doesn't work

  4. #23
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::copy copies only 3kb

    Now I am completely out of ideas, I've just splitted the code and made the archiving-copy side, which was presented, as a separate application which I am running when all files are ready to be copied. However it still doesn't work and I don't know why

  5. #24
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile::copy copies only 3kb

    Are you able to sucessfully and properly detect when the file is ready to be copied? How do you do that? Because blocking signals from the file watcher is probably not going to give you the result you expect.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #25
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::copy copies only 3kb

    Now I'm not blocking anything, I made a separate program and I run it when copied all files. Basically I tried the manual approach to the problem but I still get the same result, firstly I thought that was the problem of QFileSytemWatcher signal etc. but it didn't get the right result.

  7. #26
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile::copy copies only 3kb

    So the following also copies 3kB of the file? Try it for different files in different directories.

    Qt Code:
    1. int main(int argc, char **argv){
    2. QFIle::copy(argv[1], "/tmp/testfile");
    3. return 0;
    4. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #27
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::copy copies only 3kb

    You've enlighten but but sth to test and before I do those copies I am doing my method for doing the anonimization of the files when comment it the files are copied well, I moved it and try to anonimize the copied files but it also "corupts" the files :/ The function looks like this:

    Qt Code:
    1. void ArchiveDicom::anonymous(QString path, QString file)
    2. {
    3. DcmFileFormat fileformat;
    4. OFCondition status = fileformat.loadFile(file.toStdString().c_str());
    5.  
    6. if (status.good())
    7. {
    8. OFString patientName;
    9. if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientName).good())
    10. {
    11. QString currentPatientName(patientName.c_str());
    12.  
    13. if(currentPatientName == lastPatientName)
    14. {
    15. writeToAnonym(lastGenNum, path, fileformat, currentPatientName, file);
    16. }
    17. else
    18. {
    19. std::string randNum = generateNumber();
    20. writeToAnonym(randNum, path, fileformat, currentPatientName, file);
    21. lastPatientName = currentPatientName;
    22. lastGenNum = randNum;
    23. }
    24. }
    25. else
    26. std::cerr << "Error: cannot access Patient's Name!" << endl;
    27. }
    28. else
    29. std::cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
    30. }
    To copy to clipboard, switch view to plain text mode 

    Basically the function changes the TAG, in the .dcm file, which consists Patient Name and replaces it with some random numbers then stores the patient name which was readed.

  9. #28
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile::copy copies only 3kb

    So does my example work or not?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #29
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::copy copies only 3kb

    I found that my method works well in copying but there is sth wrong with the function I wrote above.

  11. #30
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile::copy copies only 3kb

    Without knowing what your functions do it's not possible to provide any assistance.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #31
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::copy copies only 3kb

    Quote Originally Posted by camol View Post
    You've enlighten but but sth to test and before I do those copies I am doing my method for doing the anonimization of the files when comment it the files are copied well, I moved it and try to anonimize the copied files but it also "corupts" the files :/ The function looks like this:

    Qt Code:
    1. void ArchiveDicom::anonymous(QString path, QString file)
    2. {
    3. DcmFileFormat fileformat;
    4. OFCondition status = fileformat.loadFile(file.toStdString().c_str());
    5.  
    6. if (status.good())
    7. {
    8. OFString patientName;
    9. if (fileformat.getDataset()->findAndGetOFString(DCM_PatientName, patientName).good())
    10. {
    11. QString currentPatientName(patientName.c_str());
    12.  
    13. if(currentPatientName == lastPatientName)
    14. {
    15. writeToAnonym(lastGenNum, path, fileformat, currentPatientName, file);
    16. }
    17. else
    18. {
    19. std::string randNum = generateNumber();
    20. writeToAnonym(randNum, path, fileformat, currentPatientName, file);
    21. lastPatientName = currentPatientName;
    22. lastGenNum = randNum;
    23. }
    24. }
    25. else
    26. std::cerr << "Error: cannot access Patient's Name!" << endl;
    27. }
    28. else
    29. std::cerr << "Error: cannot read DICOM file (" << status.text() << ")" << endl;
    30. }
    To copy to clipboard, switch view to plain text mode 

    Basically the function changes the TAG, in the .dcm file, which consists Patient Name and replaces it with some random numbers then stores the patient name which was readed.




    I wrote this above what it does and I can't figure out why it is wrong

  13. #32
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile::copy copies only 3kb

    Well, I don't know what generateNumber(), writeToAnonym, DcmFileFormat, OFCondition and OFString do.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #33
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::copy copies only 3kb

    Three last items are members of DCMTK library for DICOM files. GenerateNumber-generates simply a random number which is placed instead of patient name in the TAG .dcm file, and writeToAnonym writes the path of the file and what was in the TAG in .dcm file to the txt file.

  15. #34
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile::copy copies only 3kb

    And at which point your code starts malfunctioning?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #35
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::copy copies only 3kb

    What you exactly mean? I am just manually putting files in folders to my INPUT folder and the just run from console my from which does the anonimization and copies the files to another directory and I see that is sth wrong with that function in writeToAnonym:
    Qt Code:
    1. void ArchiveDicom::writeToAnonym(std::string num, QString path, DcmFileFormat fileformat, QString currentPatientName, QString file)
    2. {
    3. if (anonymFile->open(QIODevice::ReadWrite | QIODevice::Append) == true)
    4. {
    5. QTextStream out(anonymFile);
    6. out << path << " " << currentPatientName << endl;
    7. anonymFile->close();
    8. fileformat.getDataset()->putAndInsertString(DCM_PatientName, num.c_str());
    9. fileformat.saveFile(file.toStdString().c_str());
    10. }
    11. else
    12. {
    13. QTextStream(stdout)<<"couldn't open anonym.an file, so I didn't anonymize the file"<<endl;
    14. }
    15. }
    To copy to clipboard, switch view to plain text mode 

    this line is stinky fileformat.saveFile(file.toStdString().c_str()); I got this from the site from the example from DCMTK usage, when I comment this everything works so, fortunetelly coping is ok but without this line the changes described above won't take place.

  17. #36
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QFile::copy copies only 3kb

    Quote Originally Posted by camol View Post
    What you exactly mean?
    I mean your code is not a black box. You can do more than just feed it with data and see if the result is correct. I assume you have some algorithm that the code should implement and at different stages of the algorithm the code produces some intermediate results. So I'm asking at which point those results start differing from what should be happening according to your algorithm.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  18. #37
    Join Date
    Mar 2011
    Posts
    53
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFile::copy copies only 3kb

    I see. I try simply anonymize the files. After opening->reading PatientName tag everything is ok, but the I write to the file in the place of PatientName then I have to save the file and I get the file corrupted.


    I think I got I will report my result in short time
    Last edited by camol; 20th April 2011 at 23:39.

Similar Threads

  1. QFile &QFile::operator= is private
    By Fallen_ in forum Newbie
    Replies: 1
    Last Post: 15th March 2011, 15:08
  2. QTemporaryFile and Qfile::copy()
    By ChrisW67 in forum Newbie
    Replies: 2
    Last Post: 23rd April 2009, 23:32
  3. QPrintDialog: settings number of copies
    By nedlab in forum Qt Programming
    Replies: 1
    Last Post: 2nd December 2008, 19:22
  4. copies file doesn't work well
    By dreamer in forum Qt Programming
    Replies: 3
    Last Post: 10th May 2008, 22:00
  5. How many copies of Signal parameters
    By Doug Broadwell in forum Newbie
    Replies: 3
    Last Post: 2nd December 2006, 21:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.