本文整理汇总了C++中QVariant::toCString方法的典型用法代码示例。如果您正苦于以下问题:C++ QVariant::toCString方法的具体用法?C++ QVariant::toCString怎么用?C++ QVariant::toCString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QVariant
的用法示例。
在下文中一共展示了QVariant::toCString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
QCString fromQVariant<QCString>(const QVariant & s)
{
return s.toCString();
};
示例2: process
//.........这里部分代码省略.........
QVariant val;
QString propname(_props.at(j));
#if QT_VERSION >= 300
const QMetaProperty* prop = _m->property (j,true);
#else
const QMetaProperty* prop = _m->property (propname,true);
#endif
QString proptype;
if(prop){
proptype = prop->type();
att2->setText(2,proptype);
/*
QListViewItem * att3 = new QListViewItem(att2,"Writable",(prop->writable()?"True":"False"));
att3->setPixmap(0,__pixatt);
att3 = new QListViewItem(att2,att3,"Designable",(prop->designable()?"True":"False"));
att3->setPixmap(0,__pixatt);
*/
}
val = obj->property(propname);
if(!val.isValid())att2->setText(1,"Invalid");
else if(prop->isEnumType()){
att2->setText(1,prop->valueToKey(val.toInt()));
}
else if(prop->isSetType()){
QStrList st = prop->valueToKeys(val.toInt());
QString t = st.at(0);
for(uint i= 1; i < st.count(); i++)t+='/'+st.at(i);
att2->setText(1,t);
}
else if(val.type() == QVariant::String)att2->setText(1,'"'+val.toString()+'"');
else if(val.type() == QVariant::CString)att2->setText(1,'"'+val.toCString()+'"');
else if(val.type() == QVariant::Bool){
if(val.toBool())att2->setText(1,"True");
else att2->setText(1,"False");
}
else if(val.type() == QVariant::Int)att2->setText(1,QString::number(val.toInt()));
else if(val.type() == QVariant::UInt)att2->setText(1,QString::number(val.toUInt()));
else if(val.type() == QVariant::Double)att2->setText(1,QString::number(val.toDouble()));
else if(val.type() == QVariant::Rect){
const QRect r = val.toRect();
att2->setText(1,'[' + QString::number(r.left()) + ',' + QString::number(r.top())+
',' + QString::number(r.right()) + ',' + QString::number(r.bottom())+']');
}
else if(val.type() == QVariant::Region){
const QRegion reg = val.toRegion();
QRect r = reg.boundingRect();
att2->setText(1,'[' + QString::number(r.left()) + ',' + QString::number(r.top())+
',' + QString::number(r.right()) + ',' + QString::number(r.bottom())+"],");
}
else if(val.type() == QVariant::Size){
const QSize s = val.toSize();
att2->setText(1,'[' + QString::number(s.width()) + ',' + QString::number(s.height())+']');
}
else if(val.type() == QVariant::Point){
const QPoint p = val.toPoint();
att2->setText(1,'[' + QString::number(p.x()) + ',' + QString::number(p.y())+']');
}
else if(val.type() == QVariant::Color){
const QColor c = val.toColor();
att2->setText(1,'[' + QString::number(c.red()) + ',' +
QString::number(c.green()) + ',' +
QString::number(c.blue()) + ']');
}
示例3: variantToElement
bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e)
{
bool ok = true;
clearAttributes(e);
switch (v.type())
{
case QVariant::String:
e.setTagName("string");
e.setAttribute("value", v.toString().utf8());
break;
case QVariant::CString:
e.setTagName("string");
e.setAttribute("value", v.toCString());
break;
case QVariant::Int:
e.setTagName("int");
e.setAttribute("value", v.toInt());
break;
case QVariant::UInt:
e.setTagName("uint");
e.setAttribute("value", v.toUInt());
break;
case QVariant::Double:
e.setTagName("double");
e.setAttribute("value", v.toDouble());
break;
case QVariant::Bool:
e.setTagName("bool");
e.setAttribute("value", boolString(v.toBool()));
break;
case QVariant::Color:
{
e.setTagName("color");
QColor color = v.toColor();
e.setAttribute("red", color.red());
e.setAttribute("green", color.green());
e.setAttribute("blue", color.blue());
}
break;
case QVariant::Pen:
{
e.setTagName("pen");
QPen pen = v.toPen();
e.setAttribute("red", pen.color().red());
e.setAttribute("green", pen.color().green());
e.setAttribute("blue", pen.color().blue());
e.setAttribute("style", pen.style());
e.setAttribute("cap", pen.capStyle());
e.setAttribute("join", pen.joinStyle());
}
break;
case QVariant::Brush:
{
e.setTagName("brush");
QBrush brush = v.toBrush();
e.setAttribute("red", brush.color().red());
e.setAttribute("green", brush.color().green());
e.setAttribute("blue", brush.color().blue());
e.setAttribute("style", brush.style());
}
break;
case QVariant::Point:
{
e.setTagName("point");
QPoint point = v.toPoint();
e.setAttribute("x", point.x());
e.setAttribute("y", point.y());
}
break;
case QVariant::Rect:
{
e.setTagName("rect");
QRect rect = v.toRect();
e.setAttribute("x", rect.x());
e.setAttribute("y", rect.y());
e.setAttribute("width", rect.width());
e.setAttribute("height", rect.height());
}
break;
case QVariant::Size:
{
e.setTagName("size");
QSize qsize = v.toSize();
e.setAttribute("width", qsize.width());
e.setAttribute("height", qsize.height());
}
break;
case QVariant::Font:
{
e.setTagName("font");
QFont f(v.toFont());
e.setAttribute("family", f.family());
e.setAttribute("pointsize", f.pointSize());
e.setAttribute("bold", boolString(f.bold()));
e.setAttribute("italic", boolString(f.italic()));
e.setAttribute("underline", boolString(f.underline()));
e.setAttribute("strikeout", boolString(f.strikeOut()));
}
//.........这里部分代码省略.........
示例4: variantToElement
bool DomConvenience::variantToElement(const QVariant& v, QDomElement& e)
{
bool ok = true;
clearAttributes(e);
switch (v.type())
{
case QVariant::String:
e.setTagName("string");
e.setAttribute("value", v.toString().utf8());
break;
case QVariant::CString:
e.setTagName("string");
e.setAttribute("value", v.toCString());
break;
case QVariant::Int:
e.setTagName("int");
e.setAttribute("value", v.toInt());
break;
case QVariant::UInt:
e.setTagName("uint");
e.setAttribute("value", v.toUInt());
break;
case QVariant::Double:
e.setTagName("double");
e.setAttribute("value", v.toDouble());
break;
case QVariant::Bool:
e.setTagName("bool");
e.setAttribute("value", boolString(v.toBool()));
break;
case QVariant::Color:
{
e.setTagName("color");
QColor color = v.toColor();
e.setAttribute("red", color.red());
e.setAttribute("green", color.green());
e.setAttribute("blue", color.blue());
}
break;
case QVariant::Point:
{
e.setTagName("point");
QPoint point = v.toPoint();
e.setAttribute("x", point.x());
e.setAttribute("y", point.y());
}
break;
case QVariant::Rect:
{
e.setTagName("rect");
QRect rect = v.toRect();
e.setAttribute("x", rect.x());
e.setAttribute("y", rect.y());
e.setAttribute("width", rect.width());
e.setAttribute("height", rect.height());
}
break;
case QVariant::Size:
{
e.setTagName("size");
QSize qsize = v.toSize();
e.setAttribute("width", qsize.width());
e.setAttribute("height", qsize.height());
}
break;
case QVariant::Font:
{
e.setTagName("font");
QFont f(v.toFont());
e.setAttribute("family", f.family());
e.setAttribute("pointsize", f.pointSize());
e.setAttribute("bold", boolString(f.bold()));
e.setAttribute("italic", boolString(f.italic()));
e.setAttribute("underline", boolString(f.underline()));
e.setAttribute("strikeout", boolString(f.strikeOut()));
}
break;
case QVariant::SizePolicy:
{
e.setTagName("sizepolicy");
QSizePolicy sp(v.toSizePolicy());
e.setAttribute("hsizetype", sp.horData());
e.setAttribute("vsizetype", sp.verData());
#if (QT_VERSION >= 300)
e.setAttribute("horstretch", sp.horStretch());
e.setAttribute("verstretch", sp.verStretch());
#endif
}
break;
case QVariant::Cursor:
e.setTagName("cursor");
e.setAttribute("shape", v.toCursor().shape());
break;
case QVariant::StringList:
{
e.setTagName("stringlist");
uint j;
//.........这里部分代码省略.........