/** * argv[1]: infile * argv[2]: outfile */ int main(int argc, char * argv[]) { QApplication app(argc, argv); QTextCodec::setCodecForTr(QTextCodec::codecForName("gb18030")); bool output = false; QString infile; QString outfile; if ( argc > 2 ) { outfile = QString(argv[2]); } if ( argc > 1 ) { infile = QString(argv[1]); } if ( infile.isEmpty() ) { printf("empty infile."); help(); return -1; } if ( outfile.isEmpty() ) { outfile = "stdout.png"; output = true; } QSvgWidget * svg = new QSvgWidget(0); svg->load(infile); svg->resize(800, 400); /* */ QPixmap pixmap = QPixmap(); pixmap = QPixmap::grabWidget((QWidget*)svg); if ( output ) { QByteArray bytes; QBuffer buf(&bytes); buf.open(QIODevice::ReadWrite); pixmap.save(&buf, "PNG"); printf(buf.data().data()); exit(0); } else { pixmap.save(outfile); } return app.exec(); }
int main(int argc, char *argv[]) { QApplication app(argc, argv); app.setOrganizationName("QtProject"); app.setApplicationName("Application Example"); initDb(); QMainWindow mainWin; mainWin.show(); // QPlainTextEdit* textEdit = new QPlainTextEdit(); // QToolBar* fileToolBar = mainWin.addToolBar("File"); QSvgWidget* mySvg = new QSvgWidget(); vector<string> students(10); students = { "eins", "zwei", "drei" }; StudentList *studentListW = new StudentList(students); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(studentListW); mainLayout->addWidget(mySvg); QWidget *centralWidget = new QWidget; centralWidget->setLayout(mainLayout); mainWin.setCentralWidget(centralWidget); mySvg->load(QString(RESOURCES_PATH "zeugnis.svg")); QFile file(QString(RESOURCES_PATH "zeugnis.svg")); QDomDocument document; file.open(QIODevice::ReadOnly | QIODevice::Text); document.setContent(&file); QDomElement root = document.firstChildElement(); QDomNodeList nodes = root.elementsByTagName("tspan"); for(int i = 0; i < nodes.count(); i++) { QDomNode elm = nodes.at(i); if(elm.isElement()) { QDomElement element = elm.toElement(); QString attribute = element.attribute("id"); if(attribute == "tspan4167") { QString elementText = element.text(); std::cout << elementText.toStdString() << std::endl; QDomText newTextNode = document.createTextNode("Hello, World"); QDomNodeList oldTextNodes = element.childNodes(); qDebug() << "# nodes = " << oldTextNodes.count(); for (int i=0; i < oldTextNodes.count(); i++) { // element.removeChild(oldTextNodes.at(i)); qDebug() << oldTextNodes.at(i).toElement().text(); } element.appendChild(newTextNode); } } } mySvg->load(document.toByteArray()); file.close(); return app.exec(); }