[solved]Unable to open resource file
-
Hi,
I added a resource file "myresourcestuff.qrc" to my project "StringFinder"
StringFinder.pro:
@
QT += core guigreaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = StringFinder
TEMPLATE = app
INCLUDEPATH += .SOURCES += main.cpp
stringfinder.cppHEADERS += stringfinder.h
FORMS += stringfinder.ui
RESOURCES += myresourcestuff.qrc
@and the "myresourcestuff.qrc" looks like this:
@
<RCC>
<qresource prefix="/new/prefix1">
<file>stuff.txt</file>
</qresource>
</RCC>
@"stuff.txt" is located on the same path as the .ccp, .h, .qrc - files.
Now I'm trying to access that file in "stringfinder.cpp"
@
// works
//QFile myFile("C:/research/Qt/Qt5.2.0/Tools/QtCreator/bin/StringFinder/stuff.txt");
// doesn't work
QFile myFile(":/new/prefix1/stuff.txt");if(myFile.exists()){ ui->textEdit->setText("opening file"); myFile.open(QIODevice::ReadOnly); QTextStream textStream(&myFile); QString line = textStream.readAll(); myFile.close(); ui->textEdit->setPlainText(line); QTextCursor textCursor = ui->textEdit->textCursor(); textCursor.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor, 1); } else { ui->textEdit->setText("File not found"); }
@
but it won't open, myFile.exists() returns "false" :/
Can anyone help please? A minimal project is uploaded here: http://depot.tu-dortmund.de/get/ck3bx
Best,
Ben -
This should work without any problem. Just check the file extn. Some times it will somestuff.txt.tx. It may not be visible in the windows explorer. This is the only issue I suspect now.
-
Thanks, “clean”, “qmake”, “rebuild all” was the solution!!