2009-08-31 80 views

回答

2

由于帕维尔说,QtSvg是我相信的方式。这很容易使用,但在我们的团队中,我们遇到了与QtSvg相关的性能问题,特别是在Linux上。所以我们决定直接解析SVG文件XML并使用Qt本身进行渲染。事实证明这要快得多。

伪代码: -

// Read the SVG file using XML parser (SAX) 
void SvgReader::readFile() 
{ 
    QFile file(<some svg filename>); 
    if (!file.open(QFile::ReadOnly | QFile::Text)) { 
    qWarning("Cannot open file"); 
    return; 
    } 
    QString localName; 
    QXmlStreamAttributes attributes; 
    pXml = new QXmlStreamReader(&file); 
    pXml->setNamespaceProcessing(false); 
    while (!pXml->atEnd()) { 
    switch (pXml->readNext()) { 
     case QXmlStreamReader::StartElement: 
      localName = pXml->name().toString(); 
      if (localName.compare(<some element path>) == 0) { 
      attributes = pXml->attributes(); 
      QStringRef data = attributes.value(<some attribute name>); 
      // parse/use your data; 
      } 
     // similarly other case statements 
    } 
    } 
} 
1

QtSvg模块可能会有帮助。