Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalence for QString::arg() in QML

Tags:

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" 
like image 432
s4eed Avatar asked Oct 06 '12 08:10

s4eed


People also ask

What is QString C++?

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.

How do you declare a QString?

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.

What is qsTr in QML?

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.


1 Answers

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

like image 142
Dickson Avatar answered Oct 03 '22 21:10

Dickson