[Qt-qml] Custom QML types and strings

Harri Pasanen harri at mpaja.com
Wed Dec 28 16:22:26 CET 2011


Hi,

I wrote my custom QML type, using Qt 4.7.4.
It is working just fine, except when I run using it I keep getting 
messages like:

QColor::setNamedColor: Unknown color name 'mpaja.lvl'


Comes from here:


void QColor::setNamedColor(const QString &name)
{
if (!setColorFromString(name))
qWarning("QColor::setNamedColor: Unknown color name '%s'", 
name.toLatin1().constData());
}


I traced it a bit, and it seems to be triggered from

QVariant QDeclarativeStringConverters::variantFromString(const QString &s)
{
     if (s.isEmpty())
         return QVariant(s);
     bool ok = false;
     QRectF r = rectFFromString(s, &ok);
     if (ok) return QVariant(r);
     QColor c = colorFromString(s, &ok); <<<===  Here
     if (ok) return QVariant(c);
     QPointF p = pointFFromString(s, &ok);
     if (ok) return QVariant(p);
     QSizeF sz = sizeFFromString(s, &ok);
     if (ok) return QVariant(sz);
     QVector3D v = vector3DFromString(s, &ok);
     if (ok) return qVariantFromValue(v);

     return QVariant(s);
}

I'm guessing that when ever a parameter is passed from QML to C++ it 
gets converted to QVariant, which makes a best guess at the underlying type.

But I'm a bit puzzled why only some of the strings elicit this warning.

My custom type looks like:

Spoke { name: "MPaja"; value: "mpaja.lvl" }

and I'm getting a warning for each "value:", but not for "name:"

Is there some naming convention or other method that I should be aware 
off to avoid this needless warning?

Thanks,

Harri








Is there a way hint at valid supported types, or otherwise silence these





More information about the Qt-qml mailing list