在Qt资源系统中读取和写入文件(qt 5.0.2) [英] Reading from and writing to file in The Qt Resource System (qt 5.0.2)

查看:204
本文介绍了在Qt资源系统中读取和写入文件(qt 5.0.2)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的代码。我使用Qt_5_0_2_MSVC2012_64bit释放。我无法读取该文件。我得到调试错误消息无法打开文件阅读。我有资源文件有一些问题。任何想法如何我可以解决它?谢谢!

I have the code below. I am using Qt_5_0_2_MSVC2012_64bit-Release. I am not able to read the file. I get the debug error message of "Cannot open file for reading".There is some problem for me with resource files. Any idea how I can fix it? Thanks!

#include <QCoreApplication>
#include <QFile>
#include <QString>
#include <QDebug>
#include <QTextStream>
#include <QResource>
#include <QIODevice>


void Read(QString Filename){
    QFile mFile(Filename);

    if(!mFile.open(QFile::ReadOnly | QFile::Text)){
        qDebug() << "could not open file for read";
        return;
    }

        QTextStream in(&mFile);
        QString mText = in.readAll();

        qDebug() << mText;

        mFile.close();



}
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    Read(":/MyFiles/myfile.txt");
    return a.exec();
}


推荐答案

错误字符串为未知错误。
解决方案是从@ gatto的回答中添加 INCLUDEPATH + =。,并从菜单中运行命令:

I had same problem. The Error string was "Unknown error".
Solution was to add INCLUDEPATH += . from @gatto's answer and run commands from menu:

1. Build -> Clean all
2. Build -> Run qmake
3. Build -> Rebuild All

这篇关于在Qt资源系统中读取和写入文件(qt 5.0.2)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆