April 29, 2012

Deleted Member # 1e05d Deleted Member # 1e05d
Lab Rat
38 posts

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:

  1. QFSFileEngine::open: No file name specified

Here is the code snippet:

  1. void FtpClientDlg::selectFile() {
  2.     QString fileName;
  3.     QString files = QFileDialog::getOpenFileName(this, tr("Select File"), "/");
  4.     if (files.isEmpty())
  5.         return;
  6.     file = new QFile(fileName);
  7.     Q_ASSERT(file != NULL);
  8.     if(!file->open(QIODevice::ReadWrite))  {
  9.         ui->statusLabel->setText("open error "+file->fileName());
  10.         return;
  11.     }
  12.     ui->statusLabel->setText("Upload start");
  13.     ftp->put(file,fileName);
  14.     ui->statusLabel->setText("Upload end");
  15. }

7 replies

April 29, 2012

koahnig koahnig
Mad Scientist
2193 posts

Where do you assign a file name to “fileName”?
This string has to be empty when used.

April 29, 2012

Deleted Member # 1e05d Deleted Member # 1e05d
Lab Rat
38 posts

I am trying to follow an example, so I am not sure I understand the code very well. What should I be looking for?

April 29, 2012

Deleted Member # 1e05d Deleted Member # 1e05d
Lab Rat
38 posts

From what I understand, this part is not working correctly:

  1. 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.

April 29, 2012

koahnig koahnig
Mad Scientist
2193 posts

  1. void FtpClientDlg::selectFile() {
  2.     QString fileName;
  3.     // QString files = QFileDialog::getOpenFileName(this, tr("Select File"), "/");
  4.     // if (files.isEmpty())
  5.     //    return;
  6.     file = new QFile(fileName);
  7.     // Q_ASSERT(file != NULL);
  8.     //if(!file->open(QIODevice::ReadWrite))  {
  9.     //     ui->statusLabel->setText("open error "+file->fileName());
  10.     //    return;
  11.     //}
  12.     //ui->statusLabel->setText("Upload start");
  13.     //ftp->put(file,fileName);
  14.     //ui->statusLabel->setText("Upload end");
  15. }

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.

April 29, 2012

Deleted Member # 1e05d Deleted Member # 1e05d
Lab Rat
38 posts

I understand your question now, thank you. When I do:

  1. 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?

April 29, 2012

Deleted Member # 1e05d Deleted Member # 1e05d
Lab Rat
38 posts

So I made some changes and it does not go to the error message anymore.

It now puts the file in the remote location.

  1. void FtpClientDlg::selectFile() {
  2. *    QString files = QFileDialog::getOpenFileName(this, tr("Select File"), "/");
  3.     if (files.isEmpty())
  4.         return;
  5.  
  6.     QString fileName = QFileInfo(files).fileName();
  7.  
  8.     file = new QFile(fileName);
  9.     Q_ASSERT(file != NULL);
  10.     if(!file->open(QIODevice::ReadWrite))  {
  11.         ui->statusLabel->setText("open error "+file->fileName());
  12.         return;
  13.     }
  14.     ui->statusLabel->setText("Upload start");
  15.     ftp->put(file,fileName);
  16.     ui->statusLabel->setText("Upload end");
  17. }

However, the Dialog window does not automatically update to show the new files. Any idea how to get that?

April 30, 2012

koahnig koahnig
Mad Scientist
2193 posts

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 [qt-project.org] 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 [qt-project.org] and you may want to have a look to QNetworkAccessManager and QNetworkReply.

 
  ‹‹ Segmentation fault in QGraphicsView::setScene()      QtCreator c++ editor ››

You must log in to post a reply. Not a member yet? Register here!