PDA

View Full Version : copy file/s from QFileDialog



raphaelf
4th July 2006, 12:18
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

ChristianEhrlicher
4th July 2006, 12:41
Take a look at the doc:
http://doc.trolltech.com/3.3/qfiledialog.html#selectedFiles-prop

raphaelf
4th July 2006, 13:07
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 :crying:



QString file = QFileDialog::getOpenFileName(
"/home",
"Images (*.doc)",
this,
"open file dialog",
"Choose a file" );


FileInfo fi( file);
String base = fi.baseName(TRUE);

QUrlOperator *op = new QUrlOperator();
QString src = file;

QString target = "D:/temp/" + base + "";
QMessageBox::information(this,"target",target);
op->copy(src, target, false, false);

ChristianEhrlicher
4th July 2006, 13:17
once more - RTM
http://doc.trolltech.com/4.1/qfileinfo.html#fileName

raphaelf
4th July 2006, 14:26
Hi, thank for your help :)
It works. Here the examples:



/*Example vor copy one file
QString file = QFileDialog::getOpenFileName(
"/home",
"Images (*.doc)",
this,
"open file dialog",
"Choose a file" );

QFileInfo fi( file);
QString base = fi.fileName();
QUrlOperator *op = new QUrlOperator();
QString src = file;

QString target = "D:/temp/" + base;
op->copy(src, target, false, false);
*/


/*Example vor copy one or more files*/
QStringList files = QFileDialog::getOpenFileNames(
"All files (*.*)",
"",
this,
"open files dialog",
"Select one or more files to open" );

QStringList list = files;
QStringList::Iterator it = list.begin();
while( it != list.end() ) {
QFileInfo fi( *it);
QString base = fi.fileName();
QUrlOperator *op = new QUrlOperator();
QString src = *it;
QString target = "D:/temp/" + base;
op->copy(src, target, false, false);
++it;
}