久久久久久久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一区二区三区 | 在线播放中文字幕 | 99爱免费| 欧美一区不卡 | 精品久久久久久久久久久久久 | 久久国产成人 | 91精品国产综合久久久久久首页 | 国产综合视频 | 国产国拍亚洲精品av | 精品国产一区二区三区成人影院 | 嫩草影院黄 | 91精品久久久久久久久久入口 | 亚洲福利电影网 | 一区二区三区四区在线视频 | 91免费观看视频 | 欧美亚洲第一区 | 翔田千里一区二区 | 日韩久久久一区二区 | 亚洲精品在线播放 | 日韩精品免费一区 | 国产午夜精品一区二区三区在线观看 | 日日欧美| 日本中文字幕日韩精品免费 | 精品一区二区三区在线视频 | 欧美一a一片一级一片 | 欧美日韩中文国产一区发布 | 国产91成人| 视频一区二区中文字幕 | 四虎成人精品永久免费av九九 | 亚洲欧美日韩国产综合 | 欧美一区二区大片 | 中文字幕在线一 |