qt qstring to float

#include <QCoreApplication>
#include <QString>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    // Step 1: Define a QString variable
    QString str = "123.45";

    // Step 2: Convert QString to a QByteArray
    QByteArray byteArray = str.toUtf8();

    // Step 3: Convert QByteArray to a const char pointer
    const char *charData = byteArray.constData();

    // Step 4: Use the atof function to convert const char pointer to a float
    float floatValue = atof(charData);

    // Step 5: Print the float value
    qDebug() << "Float value: " << floatValue;

    return a.exec();
}