首页 > 代码库 > QT实践
QT实践
这两天工作搞了下QT,主要是为了实现一个功能,跨平台用的。功能是这样的,根据一个页面表单进行选择元素最后生成一个xml文件发送到手机上,因为之前实现了xmpp发送文件的作用,所以现在只需要根据文件生成一个xml文件。中途还算顺利,两天搞定!
最终创建xml的代码就是这一段:
void hellodialog::create_Xml()
{
QString fileName = QFileDialog::getSaveFileName(this,"Save","",".xml");
QFile file(fileName);
if(!file.open(QIODevice::WriteOnly|QIODevice::Text))
{
return ;
}
QDomDocument document;
QString strHeader( "version=\"1.0\" encoding=\"UTF-8\"" );
document.appendChild( document.createProcessingInstruction("xml", strHeader) );
QDomElement root_elem = document.createElement("node");
document.appendChild(root_elem);
QDomElement child1 = document.createElement("component");
child1.setAttribute("type","Visualable");
root_elem.appendChild(child1);
QDomElement child2 = document.createElement("component");
child2.setAttribute("type","ProxyDeform");
root_elem.appendChild(child2);
QString mesh ="Model:";
mesh += fileNameMesh;
mesh += ":clone";
QDomElement item1 = document.createElement("attribute");
item1.setAttribute("name","Model");
item1.setAttribute("value",mesh);
child1.appendChild(item1);
QDomElement item2 = document.createElement("attribute");
item2.setAttribute("name","Is build Tangent");
item2.setAttribute("value",isBuildTangent);
child1.appendChild(item2);
QString material = "name=";
material += comboBoxDiff;
material += ",specular=";
material += lineEditR;
material += " ";
material += lineEditG;
material += " ";
material += lineEditB;
material += " ";
material += lineEditE;
material += ",bumpiness=";
material += bumpiness;
material += ",cull=";
material += comboBoxCull;
material += ",Texture=";
material += diffPicture;
QDomElement item3 = document.createElement("attribute");
item3.setAttribute("name","MaterialName");
item3.setAttribute("value",material);
child1.appendChild(item3);
QDomElement item4 = document.createElement("attribute");
item4.setAttribute("name","Z Modify");
item4.setAttribute("value",modifyZ);
child1.appendChild(item4);
QString vertex;
vertex += "VertexProxyTable:";
vertex += fileNameProxy;
QDomElement item5 = document.createElement("attribute");
item5.setAttribute("name","VertexProxyTable");
item5.setAttribute("value",vertex);
child2.appendChild(item5);
QString object3D;
object3D += "Object3D:";
object3D += fileNameObj;
object3D += ":clone";
QDomElement item6 = document.createElement("attribute");
item6.setAttribute("name","Object3D");
item6.setAttribute("value",object3D);
child2.appendChild(item6);
QTextStream out( &file );
document.save( out, 4 );
file.close();
}如果有报一些.dll的错误的话,则需要使项目重新qmake一下,中途卡在这边一点时间。COFF的错误的话需要下载一个SP1,一般是不会碰到这种错误的,自己是因为安装VS2012后面卸载有点兼容问题吧。生成的xml格式类似下面这种:
在此记录下,自己也是第一次用QT做点东西,多掌握点东西对自己总是好的,加油!
QT实践
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。