久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何在 Qt 5 中寫入和讀取 QResource 文件?

How to write and read to/from a QResource file in Qt 5?(如何在 Qt 5 中寫入和讀取 QResource 文件?)
本文介紹了如何在 Qt 5 中寫入和讀取 QResource 文件?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

奇怪,我通過添加現有文件...將所需文件添加到資源中,文件就在那里.我運行 qmake ("Build->Run qmake") 以使文件可用.第一個問題:我無法從輸出終端向文件中寫入任何內容! 但是當我手動寫入文件時,每次運行時輸出終端都會顯示變化它.第二個問題:它仍然顯示 QIODevice::read: device not open !這是我的代碼:

#include #include #include #include #include #include void wFile(QString 文件名){QFile nFile(文件名);QTextStream str(&nFile);qDebug() <<"你想在想要的文件中寫什么:";str.readLine();if (!nFile.open(QFile::WriteOnly | QFile::Text)){qDebug() <<無法打開文件";返回;}nFile.flush();nFile.close();}無效讀取(QString文件名){QFile nFile(文件名);if(!nFile.open(QFile::ReadOnly | QFile::Text)){qDebug() <<無法打開文件進行閱讀";返回;}QTextStream in(&nFile);QString nText = in.readAll();qDebug() <<nText;nFile.close();}int main(int argc, char *argv[]){QCoreApplication a(argc, argv);QString nFilename =":/MyFiles/DocumentArminV.txt";wFile(n文件名);讀取(n文件名);返回 a.exec();}

這是代碼的輸出終端:

解決方案

保存在

目前,Qt 始終將數據直接存儲在可執行文件中,即使在操作系統為資源提供本機支持的 ??Windows、macOS 和 iOS 上也是如此....

It's strange, I add desired file into the resources via Add Existing Files..., the file is there. I run qmake ("Build->Run qmake") to make the file available. The first issue: I can't write anything into the file from output terminal! But when I manually write into the file, the output terminal shows the change every time I run it. Second issue: it still says QIODevice::read: device not open ! Here's my code:

#include <QCoreApplication>
#include <QDebug>
#include <QFile>
#include <QString>
#include <QTextStream>
#include <iostream>

void wFile(QString Filename)
{ 
  QFile  nFile(Filename);
  QTextStream str(&nFile);
  qDebug() << "what do you want to write in the desired file: ";
  str.readLine();
  if (!nFile.open(QFile::WriteOnly  | QFile::Text))
  {
    qDebug() << "could not open the file";
    return;
  }
  nFile.flush(); 
  nFile.close();
 }

void read (QString Filename){
  QFile nFile(Filename);

  if(!nFile.open(QFile::ReadOnly | QFile::Text))
  {
    qDebug() << "could not open file for reading";
    return;
  }
  QTextStream in(&nFile);
  QString nText = in.readAll();

  qDebug() << nText;
  nFile.close();
 }


int main(int argc, char *argv[])
{
 QCoreApplication a(argc, argv);
 QString nFilename =":/MyFiles/DocumentArminV.txt";

 wFile(nFilename);
 read(nFilename);

 return a.exec();
}

And here's output terminal of the code:

解決方案

The files saved in a qresource are read-only since they are part of the executable so you can not write or modify them.

docs:

Currently, Qt always stores the data directly in the executable, even on Windows, macOS, and iOS, where the operating system provides native support for resources. ...

這篇關于如何在 Qt 5 中寫入和讀取 QResource 文件?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 久久午夜影院 | 成人性视频免费网站 | 国产丝袜一区二区三区免费视频 | 日日操av | 国家一级黄色片 | 在线色网站 | 国产精品一码二码三码在线 | 午夜欧美一区二区三区在线播放 | аⅴ资源新版在线天堂 | 久久久免费毛片 | 日韩精品一区二 | 99reav| 9久久婷婷国产综合精品性色 | www国产亚洲精品 | 激情影院久久 | www4虎| 天天插天天舔 | 中文字幕一区二区三区在线观看 | 精品1区2区 | 中文字幕在线观看www | 精品一区二区三区免费毛片 | 综合网在线 | 欧美一区二区免费 | 免费毛片网站在线观看 | 国产精品海角社区在线观看 | 精品国产免费人成在线观看 | 国产一卡二卡三卡 | 一级片网站视频 | 欧美九九九 | 午夜影晥 | 一区二区三区高清不卡 | 国产一区二区三区亚洲 | 亚洲字幕在线观看 | 亚洲色图第一页 | 在线观看亚洲专区 | 日韩精品在线播放 | 久久久久久亚洲精品 | 免费看日韩视频 | 日韩精品中文字幕一区二区三区 | 久久久久国产精品一区 | 一区二区三区日本 |