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

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

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

問題描述

奇怪,我通過添加現(xiàn)有文件...將所需文件添加到資源中,文件就在那里.我運(yùn)行 qmake ("Build->Run qmake") 以使文件可用.第一個(gè)問題:我無法從輸出終端向文件中寫入任何內(nèi)容! 但是當(dāng)我手動(dòng)寫入文件時(shí),每次運(yùn)行時(shí)輸出終端都會(huì)顯示變化它.第二個(gè)問題:它仍然顯示 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() <<無法打開文件進(jìn)行閱讀";返回;}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 始終將數(shù)據(jù)直接存儲(chǔ)在可執(zhí)行文件中,即使在操作系統(tǒng)為資源提供本機(jī)支持的 ??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. ...

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

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

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 黄色在线播放 | 亚洲丝袜av | 午夜激情视频在线观看 | 中文字幕理伦片免费看 | 国产欧美精品一区二区三区 | 男女激情av | 狠狠操av | 欧美日韩91 | 中文字幕一区二区三区四区 | 一级毛片一级毛片 | 人人澡人人爽 | 日本亚洲欧美 | 99久久精品国产毛片 | 成人免费毛片男人用品 | 国产深夜福利 | 国产高清视频在线播放 | 国产a久久麻豆入口 | 色天天综合| 日本不卡中文字幕 | 国产裸体永久免费视频网站 | 亚洲天堂国产 | 日韩欧美精品一区 | 日韩在线不卡 | 久久精品视频一区二区 | 综合久久久久 | 黄色一级大片在线免费看产 | 欧美日韩免费一区二区三区 | 97精品国产露脸对白 | 一区二区高清视频 | 国产永久视频 | 人人艹人人爱 | 亚洲一区网站 | 成人免费视频网址 | 欧美日韩中文 | 91久久奴性调教 | 四虎看片| 黄色片aaa| 国产精品久久久一区二区三区 | 欧美色综合天天久久综合精品 | 国产成人在线视频 | 久久午夜视频 |