I'm wondering How I can have a string in QML that will be occupied with some arguments? Some thing like this in Qt:
QString str("%1 %2"); str = str.arg("Number").arg(12);//str = "Number 12"
QString stores unicode strings. By definition, since QString stores unicode, a QString knows what characters it's contents represent. This is in contrast to a C-style string (char*) that has no knowledge of encoding by itself.
One way to initialize a QString is simply to pass a const char * to its constructor. For example, the following code creates a QString of size 5 containing the data "Hello": QString str = "Hello"; QString converts the const char * data into Unicode using the fromAscii() function.
1. Use qsTr() for all Literal User Interface Strings. Strings in QML can be marked for translation using the qsTr(), qsTranslate(), qsTrId(), QT_TR_NOOP(), QT_TRANSLATE_NOOP(), and QT_TRID_NOOP() functions. The most common way of marking strings is with the qsTr() function.
In QML environment, the arg() function already added to the string prototype, so basically you can use the string.arg() in QML just like C++.
There is less documentation about this, but I'm sure it works in Qt 4.7 + QtQuick 1.1
Take at look at the Qt 5 doc : http://qt-project.org/doc/qt-5.0/qtqml/qml-string.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With