Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Convert QString to char

Convert QString to char

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 3.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    magda
    wrote on last edited by
    #1

    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();@
    
    1 Reply Last reply
    0
    • B Offline
      B Offline
      butterface
      wrote on last edited by
      #2

      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
      @
      latlist[3].c_str()[0]
      @

      (Did not check const correctness on this)

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi,

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

        You can use e.g.

        @latlist[3][0].toAscii();@

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • Q Offline
          Q Offline
          qxoz
          wrote on last edited by
          #4

          As SGaist wrote "QLatin1Char() is not a method it’s a constructor"
          in your case
          @latlist[3][0].toAscii();@
          is good solution. In future if you need char array or QByteArray you can use:
          @latlist[3].toLatin1()@

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved