Results 1 to 5 of 5

Thread: copy file/s from QFileDialog

  1. #1
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Cool copy file/s from QFileDialog

    Hi everybody,

    QT: 3.2.1
    OS: WinXP
    I would like to choose one or more files from the QFileDialog and copy this selected file/s to another destination.
    I was able to open the QFileDialog and choose my files.
    I should get the complete source like: "C:\temp\myfile.doc" to be able to copy this file/s to another destination.
    I tryed with dirPath from QFileDialog Library but i get just the Current Path without my filename.
    How could i get the complete path include file name like for example: "C:\temp\myfile.doc"

    Thanks
    Think DigitalGasoline

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: copy file/s from QFileDialog


  3. #3
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: copy file/s from QFileDialog

    Hi,
    Thanks for the doc, i will test it step by step.. First i will try to copy one file to another destination.
    I can open my dialog, choose a file, get the source path complete. But to copy this file to my destination i need to get my filename include filetype like "myfile.doc". In my example i get just "myfile" without filetype.
    How could i get my filename with the filetype like myfile.doc

    Qt Code:
    1. QString file = QFileDialog::getOpenFileName(
    2. "/home",
    3. "Images (*.doc)",
    4. this,
    5. "open file dialog",
    6. "Choose a file" );
    7.  
    8.  
    9. FileInfo fi( file);
    10. String base = fi.baseName(TRUE);
    11.  
    12. QUrlOperator *op = new QUrlOperator();
    13. QString src = file;
    14.  
    15. QString target = "D:/temp/" + base + "";
    16. QMessageBox::information(this,"target",target);
    17. op->copy(src, target, false, false);
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

  4. #4
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: copy file/s from QFileDialog


  5. #5
    Join Date
    Jan 2006
    Posts
    273
    Thanks
    42
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: copy file/s from QFileDialog

    Hi, thank for your help
    It works. Here the examples:

    Qt Code:
    1. /*Example vor copy one file
    2. QString file = QFileDialog::getOpenFileName(
    3. "/home",
    4. "Images (*.doc)",
    5. this,
    6. "open file dialog",
    7. "Choose a file" );
    8.  
    9. QFileInfo fi( file);
    10. QString base = fi.fileName();
    11. QUrlOperator *op = new QUrlOperator();
    12. QString src = file;
    13.  
    14. QString target = "D:/temp/" + base;
    15. op->copy(src, target, false, false);
    16. */
    17.  
    18.  
    19. /*Example vor copy one or more files*/
    20. QStringList files = QFileDialog::getOpenFileNames(
    21. "All files (*.*)",
    22. "",
    23. this,
    24. "open files dialog",
    25. "Select one or more files to open" );
    26.  
    27. QStringList list = files;
    28. QStringList::Iterator it = list.begin();
    29. while( it != list.end() ) {
    30. QFileInfo fi( *it);
    31. QString base = fi.fileName();
    32. QUrlOperator *op = new QUrlOperator();
    33. QString src = *it;
    34. QString target = "D:/temp/" + base;
    35. op->copy(src, target, false, false);
    36. ++it;
    37. }
    To copy to clipboard, switch view to plain text mode 
    Think DigitalGasoline

Similar Threads

  1. file copy in Qt 3.3.4 ?
    By npc in forum Newbie
    Replies: 6
    Last Post: 31st March 2006, 14:43
  2. implicit or shared copy?
    By SkripT in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2006, 14:14
  3. how can i copy a directary using QDir
    By monaem in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2006, 12:12

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.