How to convert int to QString ?

How to convert int to QString ?

Asked on December 14, 2018 in Qt.
Add Comment


  • 3 Answer(s)

    Follow this solution:

    inti=42;
    QStrings=QString::number(i);
    

    Just try this link:

      QString::number():

    Answered on December 14, 2018.
    Add Comment

    Try this:

    To put the string within some text  forget about + operator.

    // Qt 5 + C++11
    auto i = 13;
    auto printable = QStringLiteral("My magic number is %1. That's all!").arg(i);
     
    // Qt 5
    int i = 13;
    QString printable = QStringLiteral("My magic number is %1. That's all!").arg(i);
     
    // Qt 4
    int i = 13;
    QString printable = QString::fromLatin1("My magic number is %1. That's all!").arg(i);
    
    Answered on December 14, 2018.
    Add Comment

     Convert  the  QVariant. For an int to a QString you get:

    QVariant(3).toString();
    

    A float to a string or a string to a float:

    QVariant(3.2).toString();
    QVariant("5.2").toFloat();
    
    Answered on December 14, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.