Results 1 to 2 of 2

Thread: No file name specified

  1. #1
    Join Date
    Jul 2018
    Posts
    7
    Qt products
    Qt4 Qt5
    Platforms
    Windows Android

    Default No file name specified

    I'm trying to open a file to my texteditor and I want to change and save it but it gives me that error
    QFSFileEngine::open: No file name specified

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QWidget>
    4. #include <QFileDialog>
    5. #include <QFile>
    6. #include <QFileInfo>
    7.  
    8.  
    9. MainWindow::MainWindow(QWidget *parent) :
    10. QMainWindow(parent),
    11. ui(new Ui::MainWindow)
    12. {
    13. ui->setupUi(this);
    14.  
    15. }
    16.  
    17. MainWindow::~MainWindow()
    18. {
    19. delete ui;
    20. }
    21.  
    22. void MainWindow::on_actionOpen_triggered()
    23. {
    24. QString file = QFileDialog::getOpenFileName(this); //this is open function
    25.  
    26. if(!file.isEmpty())
    27. {
    28.  
    29. nFile.setFileName (file);
    30. if(nFile.open (QFile::ReadOnly | QFile::Text))
    31. {
    32. nFile.fileName ()=file;
    33. QTextStream in(&nFile);
    34. QString text = in.readAll ();
    35. nFile.close();
    36.  
    37. ui->textEdit->setPlainText (text);
    38.  
    39.  
    40. }
    41. }
    42. }
    43.  
    44. void MainWindow::on_actionSave_triggered() //this is save function
    45.  
    46. {
    47. //QString file; //I tried to fix the problem with these parts
    48. //nFile.setFileName (file);
    49. if(nFile.open (QFile::WriteOnly | QFile::Text))
    50. {
    51. QTextStream out(&nFile);
    52. out << ui->textEdit->toPlainText ();
    53.  
    54. nFile.flush();
    55. nFile.close();
    56.  
    57. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: No file name specified

    Do you understand what line 32 is doing? If you think it is setting the name of the file used by the file engine, you need to review your C++ a bit more. The open() statement on line 49 is telling you exactly what is wrong: you haven't given any path to the file, so it has no clue which file you're trying to open.

    In my opinion, you shouldn't even be using QFSFileEngine in the first place. You should be using one of the higher level classes, like QFile, to access the file system.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 2
    Last Post: 13th January 2014, 07:27
  2. Replies: 4
    Last Post: 2nd October 2013, 13:57
  3. Replies: 3
    Last Post: 1st November 2010, 16:33
  4. Replies: 3
    Last Post: 28th March 2009, 15:37
  5. Replies: 3
    Last Post: 25th May 2007, 07:49

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.