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;
}