Select folder and upload all files from folder to server
-
You need to post a larger section of the code where the problem is.
Also a larger stretch of the error messages are helpful.What is the OS and compiler you are using?
wrote on 5 May 2017, 08:46 last edited by@koahnig I am using ubuntu I have already posted the code to upload file on server and for select the single file my code is void
void MainWindow::selectFileDownload() { QString downloadlocation = QFileDialog::getOpenFileName(); QDir dir = QFileInfo(downloadlocation).absoluteDir(); qDebug() << dir; qDebug() << downloadlocation; this->downloadLine->setText(downloadlocation);
}
-
@koahnig I am using ubuntu I have already posted the code to upload file on server and for select the single file my code is void
void MainWindow::selectFileDownload() { QString downloadlocation = QFileDialog::getOpenFileName(); QDir dir = QFileInfo(downloadlocation).absoluteDir(); qDebug() << dir; qDebug() << downloadlocation; this->downloadLine->setText(downloadlocation);
}
@developerNancy There is no such constructor. Please check the documentation: http://doc.qt.io/qt-5.8/qdiriterator.html
-
@developerNancy There is no such constructor. Please check the documentation: http://doc.qt.io/qt-5.8/qdiriterator.html
wrote on 5 May 2017, 09:50 last edited by@jsulm I have not Implemented directory yet it is a selected file method.
-
@jsulm I have not Implemented directory yet it is a selected file method.
wrote on 5 May 2017, 10:24 last edited by@developerNancy
Using this code
QDirIterator UploadFolderFiles(UploadFolder, QDirIterator::Subdirectories );
while (UploadFolderFiles.hasNext()) {
qDebug() << UploadFolderFiles.next();
}My output is this:
/Desktop/testingQT"
/Desktop/testingQT/Linuxapp"
/Desktop/testingQT/.."
/Desktop/testingQT/."
/Desktop/testingQT/dfgdggd"But I want only files.
-
@developerNancy
Using this code
QDirIterator UploadFolderFiles(UploadFolder, QDirIterator::Subdirectories );
while (UploadFolderFiles.hasNext()) {
qDebug() << UploadFolderFiles.next();
}My output is this:
/Desktop/testingQT"
/Desktop/testingQT/Linuxapp"
/Desktop/testingQT/.."
/Desktop/testingQT/."
/Desktop/testingQT/dfgdggd"But I want only files.
well u left out the list of files u want
so that seems to mean no files when u dont give it a list. -
well u left out the list of files u want
so that seems to mean no files when u dont give it a list.wrote on 5 May 2017, 10:54 last edited by@mrjj My output is this:
/Desktop/testingQT"
/Desktop/testingQT/Linuxapp"
/Desktop/testingQT/.."
/Desktop/testingQT/."
/Desktop/testingQT/dfgdggd"But there is . and .. also I want only files
-
well u left out the list of files u want
so that seems to mean no files when u dont give it a list.wrote on 5 May 2017, 11:47 last edited by@mrjj I want files only without . and .. means 1st is file name and second null and third also null and fourth is file name.
/Desktop/testingQT/Linuxapp"
/Desktop/testingQT/.."
/Desktop/testingQT/."
/Desktop/testingQT/dfgdggd" -
@mrjj I want files only without . and .. means 1st is file name and second null and third also null and fourth is file name.
/Desktop/testingQT/Linuxapp"
/Desktop/testingQT/.."
/Desktop/testingQT/."
/Desktop/testingQT/dfgdggd"wrote on 5 May 2017, 11:52 last edited by@developerNancy
You may have a look at http://doc.qt.io/qt-5/qdiriterator.html#QDirIterator-2 and http://doc.qt.io/qt-5/qdir.html#Filter-enum -
@developerNancy
You may have a look at http://doc.qt.io/qt-5/qdiriterator.html#QDirIterator-2 and http://doc.qt.io/qt-5/qdir.html#Filter-enumwrote on 5 May 2017, 11:53 last edited by@the_ I am new in qt I don't know how to implement too confused
-
@the_ I am new in qt I don't know how to implement too confused
wrote on 5 May 2017, 11:55 last edited by@developerNancy
Which part of the documentation don't you understand and what did you try so far? -
@developerNancy
Which part of the documentation don't you understand and what did you try so far?wrote on 5 May 2017, 12:07 last edited by@the_ I have almost done but I want only files......
-
@the_ I have almost done but I want only files......
wrote on 5 May 2017, 12:18 last edited by the_ 5 May 2017, 12:23If you only want the files within a folder just apply the correct
QDir::Filters
to theQDirIterator
.
Just a guess:QDir::Files
as can be found in http://doc.qt.io/qt-5/qdir.html#Filter-enum--EDIT
QDir::NoDotAndDotDot
is not neccessary if you useQDir::Files
as.
and..
are folders and not files. my bad, sorry -
@the_ I have almost done but I want only files......
wrote on 5 May 2017, 12:19 last edited by@developerNancy Would be great if you could provide me with some working example of this.
Thanks
-
If you only want the files within a folder just apply the correct
QDir::Filters
to theQDirIterator
.
Just a guess:QDir::Files
as can be found in http://doc.qt.io/qt-5/qdir.html#Filter-enum--EDIT
QDir::NoDotAndDotDot
is not neccessary if you useQDir::Files
as.
and..
are folders and not files. my bad, sorrywrote on 5 May 2017, 12:31 last edited by developerNancy 5 May 2017, 12:31@the_ said what I have to change
QString UploadFolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"),"/home",QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks); QDirIterator UploadFolderFiles(UploadFolder, QDirIterator::Subdirectories); while (UploadFolderFiles.hasNext()) { qDebug() << UploadFolderFiles.next(); } this->uploadLine->setText(UploadFolder);
-
@the_ said what I have to change
QString UploadFolder = QFileDialog::getExistingDirectory(this, tr("Open Directory"),"/home",QFileDialog::ShowDirsOnly| QFileDialog::DontResolveSymlinks); QDirIterator UploadFolderFiles(UploadFolder, QDirIterator::Subdirectories); while (UploadFolderFiles.hasNext()) { qDebug() << UploadFolderFiles.next(); } this->uploadLine->setText(UploadFolder);
wrote on 5 May 2017, 12:40 last edited byJust use
QDirIterator::QDirIterator(const QString &path, QDir::Filters filters, IteratorFlags flags = NoIteratorFlags)
instead ofQDirIterator::QDirIterator(const QDir &dir, IteratorFlags flags = NoIteratorFlags)
as your constructor and apply the filters you need as listed in QDir::Filters -
Just use
QDirIterator::QDirIterator(const QString &path, QDir::Filters filters, IteratorFlags flags = NoIteratorFlags)
instead ofQDirIterator::QDirIterator(const QDir &dir, IteratorFlags flags = NoIteratorFlags)
as your constructor and apply the filters you need as listed in QDir::Filterswrote on 5 May 2017, 13:10 last edited by@the_ Thanks....
-
@the_ Thanks....
Lifetime Qt Championwrote on 5 May 2017, 16:56 last edited by mrjj 5 May 2017, 16:57So in short, it is like first shown
QDirIterator it(dir, QStringList() << "*.*", QDir::Files, QDirIterator::Subdirectories);
The
QStringList() << "*.*"
tell what files you are after.
If you dont tell it, it seems to think u say "i dont want any files" which makes sense.
-
So in short, it is like first shown
QDirIterator it(dir, QStringList() << "*.*", QDir::Files, QDirIterator::Subdirectories);
The
QStringList() << "*.*"
tell what files you are after.
If you dont tell it, it seems to think u say "i dont want any files" which makes sense.
-
@mrjj
With the difference that*.*
does only match files that contain a dot but misses all files without file extension ;)Lifetime Qt Championwrote on 5 May 2017, 17:22 last edited by mrjj 5 May 2017, 17:23@the_
Good point
But will
"*"
match all files , even on windows ?
17/28