【QT】添加资源+写入txt文件

1、添加资源

项目名右键–add new file–QT resource–输入resource名 例如:“resource”

添加前缀 例如:“/”

这里写图片描述

添加文件 例如:“measure.txt”

这里写图片描述

像这样,资源就添加好了

这里写图片描述

引用 例如:

QFile path(":/resource/measure.txt");

2、写入txt文件

源代码如下:

    QFile path("results.txt");
    if (path.open(QFile::WriteOnly | QIODevice::Truncate))
    {
        QTextStream out(&path);
        out << "The answer is " << 42;
    }

猜你喜欢

转载自blog.csdn.net/m0_37557014/article/details/75725974