• 3170阅读
  • 3回复

QStreamXmlReader读取失败 [复制链接]

上一主题 下一主题
离线appledog
 

只看楼主 倒序阅读 楼主  发表于: 2018-08-17
读取画笔颜色失败,请问是什么原因呢?
bool GraphicsItem::readBaseAttributes(QXmlStreamReader *xml)
{    qreal x = xml->attributes().value(tr("x")).toDouble();    
     qreal y = xml->attributes().value(tr("y")).toDouble();  
     m_width = xml->attributes().value("width").toDouble();    
     m_height = xml->attributes().value("height").toDouble();  
     pencolor_r=xml->attributes().value("pencolor.r").toInt();
     pencolor_g=xml->attributes().value("pencolor.g").toInt();  
     pencolor_b=xml->attributes().value("pencolor.b").toInt();
}
bool GraphicsItem::writeBaseAttributes(QXmlStreamWriter *xml)
{    xml->writeAttribute(tr("rotate"),QString("%1").arg(rotation()));  
     xml->writeAttribute(tr("x"),QString("%1").arg(pos().x()));  
     xml->writeAttribute(tr("y"),QString("%1").arg(pos().y()));
     xml->writeAttribute(tr("z"),QString("%1").arg(zValue()));  
     xml->writeAttribute(tr("width"),QString("%1").arg(m_width));  
     xml->writeAttribute(tr("height"),QString("%1").arg(m_height));  
     xml->writeAttribute(tr("pencolor.r"),QString("%1").arg(m_pen.color().red()));  
     xml->writeAttribute(tr("pencolor.g"),QString("%1").arg(m_pen.color().green()));  
     xml->writeAttribute(tr("pencolor.b"),QString("%1").arg(m_pen.color().blue()));    
     return true;
}

这个是在.h文件中变量的定义:
     int getpenClor()
   {  pencolor_r=m_pen.color().red();                      
       pencolor_g=m_pen.color().green();                        
       pencolor_b=m_pen.color().blue();}
       int pencolor_r;  
       int pencolor_g;
       int pencolor_b;
}
本帖提到的人: @firebolt
离线firebolt

只看该作者 1楼 发表于: 2018-08-17
读取颜色失败是什么意思,没读出来还是读出来不对?
离线appledog

只看该作者 2楼 发表于: 2018-08-18
回 firebolt 的帖子
firebolt:读取颜色失败是什么意思,没读出来还是读出来不对? (2018-08-17 14:15) 

读不出来,打开还是随机颜色,但是存进去了
离线appledog

只看该作者 3楼 发表于: 2018-08-18
回 firebolt 的帖子
firebolt:读取颜色失败是什么意思,没读出来还是读出来不对? (2018-08-17 14:15) 

改出来了,加了一个函数setBrushColor(QColor(brushcolor_r,brushcolor_g,brushcolor_b));
快速回复
限100 字节
 
上一个 下一个