Qt World Summit: Submit your Presentation

Convert QString to char

  • How do I convert a QString to a char. When using latcardinalDirection = latlist[3].QLatin1Char(); the compiler says that QString does not have a member called QLatin1Char(). May you please assist?

    char latcardinalDirection,longcardinalDirection ;
    QString latitudestring = QInputDialog::getText(0, "Latitude"," Degrees Minutes Seconds Cardinal Direction: ",QLineEdit::Normal,"",&ok,0);

        QStringList latlist;
        latlist = latitudestring.split(" ");
        int latdegrees = latlist[0].toInt();
        int latminutes = latlist[1].toInt();
        int latseconds = latlist[2].toInt();
        latcardinalDirection = latlist[3].QLatin1Char();@

  • Normally the compiler is right saying a member is not existing if it is not.

    If you are sure that the string is set correctly you can use something like

    (Did not check const correctness on this)

  • Lifetime Qt Champion


    QLatin1Char() is not a method it's a constructor (invalid in this case)

    You can use e.g.


  • As SGaist wrote "QLatin1Char() is not a method it’s a constructor"
    in your case
    is good solution. In future if you need char array or QByteArray you can use:

Log in to reply