我无法读取和写入QByteArray数据到文件.
我的目标是将QPixmap数据保存到QByteArray中,并将QByteArray保存到文件中(能够从文件读回QByteArray并进入QPixmap).我想使用QPixmap文档中的以下代码:
QPixmap pixmap(<image path>);
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format
Run Code Online (Sandbox Code Playgroud)
在将缓冲区写入文件后,我希望能够使用QPixmap :: loadFromData()函数检索QByteArray并将其加载回QPixmap.
如果需要进一步澄清,请告诉我(我也对其他方法持开放态度,我只需要能够将QPixmap读写到文件中!:));
我目前有一个带有Ext.ux.RowEditor插件的GridPanel.行编辑器中存在四个字段:端口,IP地址,子网和DHCP.如果选中所选行的DHCP字段(复选框),我需要使其他三个字段不可编辑.
我一直试图在触发beforeedit事件时执行此代码,但无济于事......我只找到了使整个列不可编辑的方法.我的代码到目前为止:
this.rowEditor.on({
scope: this,
beforeedit: this.checkIfEditable
});
checkIfEditable:function(rowEditor, rowIndex) {
if(this.getStore().getAt(rowIndex).get('dhcp')) {
// this function makes the entire column un-editable:
this.getColumnModel().setEditable(2, false);
// I want to make only the other three fields of the current row
// uneditable.
}
}
Run Code Online (Sandbox Code Playgroud)
如果需要澄清,请告诉我.
任何有助于扩展RowEditor以完成目标功能的帮助也将非常受欢迎!
我有一个对象,我希望能够读取和写入QDataStream.标题如下:
class Compound
{
public:
Compound(QString, QPixmap*, Ui::MainWindow*);
void saveCurrentInfo();
void restoreSavedInfo(QGraphicsScene*);
void setImage(QPixmap*);
QString getName();
private:
QString name, homeNotes, addNotes, expText;
Ui::MainWindow *gui;
QPixmap *image;
struct NMRdata
{
QString hnmrText, cnmrText, hn_nmrText, hn_nmrNucl, notes;
int hnmrFreqIndex, cnmrFreqIndex, hn_nmrFreqIndex,
hnmrSolvIndex, cnmrSolvIndex, hn_nmrSolvIndex;
}*nmr_data;
struct IRdata
{
QString uvConc, lowResMethod,
irText, uvText, lowResText, highResText,
highResCalc, highResFnd, highResFrmla,
notes;
int irSolvIndex, uvSolvIndex;
}*ir_data;
struct PhysicalData
{
QString mpEdit, bpEdit, mpParensEdit, bpParensEdit,
rfEdit, phyText, optAlpha,
optConc, elemText, elemFrmla,
notes;
int phySolvIndex, optSolvIndex;
}*physical_data; …Run Code Online (Sandbox Code Playgroud) 我编写了一个多线程矩阵乘法.我相信我的方法是正确的,但我不是百分百肯定.关于线程,我不明白为什么我不能只运行一个(new MatrixThread(...)).start()而不是使用ExecutorService.
此外,当我对多线程方法与经典方法进行基准测试时,经典方法要快得多......
我究竟做错了什么?
矩阵类:
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
class Matrix
{
private int dimension;
private int[][] template;
public Matrix(int dimension)
{
this.template = new int[dimension][dimension];
this.dimension = template.length;
}
public Matrix(int[][] array)
{
this.dimension = array.length;
this.template = array;
}
public int getMatrixDimension() { return this.dimension; }
public int[][] getArray() { return this.template; }
public void fillMatrix()
{
Random randomNumber = new Random();
for(int i = 0; i < …Run Code Online (Sandbox Code Playgroud) 我希望获取给定类别的Amazon前1000种(或尽可能多)最畅销的产品。在扫描了Amazon Product Advertising API文档并通读了关于类似主题的几个问题之后(即可以获取1000本书最畅销书的Amazon ECS API和https://forums.aws.amazon.com/thread.jspa?threadID=98920) ,我仍然不确定是否应该使用产品广告API,从RSS feed中读取信息还是构建自己的抓取工具来获取此信息。重申一下,如果可能(即使需要多个请求),我希望获取的不仅仅是十大产品。
有什么想法吗?
我正在尝试编辑一个如下所示的文本文件:
TYPE=Ethernet
HWADDR=00:....
IPV6INIT=no
MTU=1500
IPADDR=192.168.2.247
...
Run Code Online (Sandbox Code Playgroud)
(它实际上是red hat Linux上的/ etc/sysconfig/network-scripts/ifcfg-文件)而不是每次我想修改它时读取和重写文件,我想我可以使用grep,sed,awk或本机文本解析Perl中提供的功能.
例如,如果我想更改文件的IPADDR字段,有没有办法直接检索和修改该行?也许是这样的
grep 'IPADDR=' <filename>
Run Code Online (Sandbox Code Playgroud)
但添加一些额外的参数来修改该行?我对基于UNIX的文本处理语言有点新意,所以请耐心等待......
谢谢!