QIODevice :: read: device does not open

I try to read from a file and paste into text editing, and it continues to say QIODevice :: read: the device does not open. The .txt file is in the same place as the .qrc and .cpp files. I followed the walkthrough from the Internet. In my opinion, they changed something when they switched from Q4 to Q5. Does anyone have any hint on how I can fix this. thanks

//My findstuff.h #ifndef FINDSTUFF_H #define FINDSTUFF_H #include <QWidget> namespace Ui {class FindStuff;} class FindStuff : public QWidget{ Q_OBJECT public: explicit FindStuff(QWidget *parent = 0); ~FindStuff(); private slots: void on_goButton_clicked(); private: Ui::FindStuff *ui; void getTextFile(); }; 
+7
source share
6 answers

If you are reading from a .qrc resource file, you must run qmake ("Build-> Run qmake" in Qt Creator) before it is available.

+7
source

You do not pass the absolute file path to QFile::open() , and you do not check the result of opening the file. In your case, this is a failure, and open() returns false, but you ignore it, and do not fix the problem (wrong path) that caused it.

This is due to updating Qt 4 β†’ Qt 5, and everything related to you suggests a misconception about the current directory that your application is facing. Generally speaking, the current directory (or working directory) is arbitrary, specific to the platform and circumstances, and is not completely controlled. If the user does not give you a file name that implicitly refers to the current working directory (for example, as the relative path specified by the command line argument), you must use absolute paths to the file or things just won’t work.

+2
source

This may be due to the Qt version, since Qt5 sometimes does not work with MSVC2010. I have Qt 5.4 and my code gave the same error when it worked with MSVC2010 OpenGL as a compiler. I manually added MinGW 32bit to use it as a compiler, and it worked. Postscript I did not install MSVC2013 for Qt 5.4., And it sometimes works with MSVC2010 OpenGL without errors, but not in this case.

0
source

I had this problem and it turned out that Qt Creator did not actually add the .qrc file to my project. I use Qt Creator 4.1.0 on a Mac, and the project view does not always fill up after creating a new project, first requiring a restart of Creator. My version of this problem may be related to this.

0
source

This has nothing to do with the Qt version. Even if your .txt file is in the same directory as your .cpp file, you still need to add this directory. I had the same problem and this simple solution worked well.

0
source

This has nothing to do with the Qt version. Even if your .txt file is in the same directory as your .cpp file, you still need to add this directory. I had the same problem and this simple solution worked well. Arman Arefi

0
source

Source: https://habr.com/ru/post/972855/


All Articles