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. Can we convert a string of type Qstring to char*?
Forum Updated to NodeBB v4.3 + New Features

Can we convert a string of type Qstring to char*?

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 4.3k 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.
  • P Offline
    P Offline
    pratik041
    wrote on last edited by
    #1

    I want to convert because i need to pass to a function which receive char* string argument.

    Pratik Agrawal

    1 Reply Last reply
    0
    • JohanSoloJ Offline
      JohanSoloJ Offline
      JohanSolo
      wrote on last edited by
      #2

      You can use QString::toStdString(), and then std::string::c_str(), and I think QString::constData() works as well.

      `They did not know it was impossible, so they did it.'
      -- Mark Twain

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fluca1978
        wrote on last edited by
        #3

        All the to_ methods of QString are useful to convert it into another type. There is also a way to convert it to "8 bits":http://doc.qt.nokia.com/latest/qstring.html#toLocal8Bit and to "qbytearray":http://doc.qt.nokia.com/latest/qstring.html#toAscii.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cincirin
          wrote on last edited by
          #4

          You can follow "this DevNet FAQ":http://developer.qt.nokia.com/faq/answer/how_can_i_convert_a_qstring_to_char_and_vice_versa

          1 Reply Last reply
          0
          • G Offline
            G Offline
            goetz
            wrote on last edited by
            #5

            Thread closed, this is a FAQ.

            http://www.catb.org/~esr/faqs/smart-questions.html

            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