QFSFileEngine::open: No file name specified
-
I all , how do I select a file from a directory? Both the file and directory is visible
to me when I run the code. When I selct a file and double click it I get the error
message and the following info:@QFSFileEngine::open: No file name specified@
Here is the code snippet:
@void FtpClientDlg::selectFile() {
QString fileName;
QString files = QFileDialog::getOpenFileName(this, tr("Select File"), "/");
if (files.isEmpty())
return;
file = new QFile(fileName);
Q_ASSERT(file != NULL);
if(!file->open(QIODevice::ReadWrite)) {
ui->statusLabel->setText("open error "+file->fileName());
return;
}
ui->statusLabel->setText("Upload start");
ftp->put(file,fileName);
ui->statusLabel->setText("Upload end");
}@ -
Where do you assign a file name to "fileName"?
This string has to be empty when used. -
I am trying to follow an example, so I am not sure I understand the code very well. What should I be looking for?
-
From what I understand, this part is not working correctly:
@file = new QFile(fileName);@
Which is why I am getting the error message. I looked at other examples
and the formating seems similar, so I am not sure what is wrong where. -
@void FtpClientDlg::selectFile() {
QString fileName;
// QString files = QFileDialog::getOpenFileName(this, tr("Select File"), "/");
// if (files.isEmpty())
// return;
file = new QFile(fileName);
// Q_ASSERT(file != NULL);
//if(!file->open(QIODevice::ReadWrite)) {
// ui->statusLabel->setText("open error "+file->fileName());
// return;
//}
//ui->statusLabel->setText("Upload start");
//ftp->put(file,fileName);
//ui->statusLabel->setText("Upload end");
}@See the relevant lines up there. Everything else is converted to comments. You declare and use, but you do not assign any content. So, it has to be empty when used.
-
I understand your question now, thank you. When I do:
@QString files = QFileDialog::getOpenFileName(this, tr("Select File"), "/");@
I see a list of files. My intention is to "double click" a file and use that to select
the fileName. How can I do that?If I want to go to simpler route, can I just change the fileName to "myfile.txt"?
Ofcourse, I think then I wont need the "QFileDialog" thing, correct? -
So I made some changes and it does not go to the error message anymore.
It now puts the file in the remote location.
@void FtpClientDlg::selectFile() {
- QString files = QFileDialog::getOpenFileName(this, tr("Select File"), "/");
if (files.isEmpty())
return;
QString fileName = QFileInfo(files).fileName(); file = new QFile(fileName); Q_ASSERT(file != NULL); if(!file->open(QIODevice::ReadWrite)) { ui->statusLabel->setText("open error "+file->fileName()); return; } ui->statusLabel->setText("Upload start"); ftp->put(file,fileName); ui->statusLabel->setText("Upload end");
}@
However, the Dialog window does not automatically update to show the new files. Any idea how to get that?
- QString files = QFileDialog::getOpenFileName(this, tr("Select File"), "/");
-
Which dialog window do you mean?
I guess you are talking about a different dialog window whose source you have not posted. This dialog window shall show the files on the ftp site?
The ftp is a command driven approach communicating with a remote site. Whatever you are doing, you have to send command for everything separately. So, if you like to have updated information of the ftp server content, you have to send another command to give you the list. Please consult "QFtp":http://qt-project.org/doc/qt-4.8/qftp.html#list documentation and probably you should also see at standard ftp approaches. Because QFtp is just providing the interface to do the same.BTW "QFtp is deprecated":http://qt-project.org/doc/qt-4.8/qftp.html#details and you may want to have a look to QNetworkAccessManager and QNetworkReply.