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. [SOLVED] Converting from QString to char
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Converting from QString to char

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 2.5k 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.
  • K Offline
    K Offline
    koresaram777
    wrote on last edited by
    #1

    Hello everybody! help please! I have no idea how to do.
    I need to convert QString, it means ui->lineEdit->text() to char, means char expr[255]? How to do it without using const char or char * or QByteArray?

    1 Reply Last reply
    0
    • mrdebugM Offline
      mrdebugM Offline
      mrdebug
      wrote on last edited by
      #2

      QString::latin1() to have const char *. If you want you can download the source of QtComPort (http://kde-apps.org/content/show.php/?content=142378) and look at the file qcserialcomport.cpp to have some conversion functions.

      Bye bye.

      Need programmers to hire?
      www.labcsp.com
      www.denisgottardello.it
      GMT+1
      Skype: mrdebug

      1 Reply Last reply
      0
      • K Offline
        K Offline
        koresaram777
        wrote on last edited by
        #3

        unfortunately i have windows ( not linux

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koresaram777
          wrote on last edited by
          #4

          [quote author="mrdebug" date="1379700265"]QString::latin1() to have const char *. If you want you can download the source of QtComPort (http://kde-apps.org/content/show.php/?content=142378) and look at the file qcserialcomport.cpp to have some conversion functions.

          Bye bye.[/quote]
          unfortunately i have windows not linux

          1 Reply Last reply
          0
          • mrdebugM Offline
            mrdebugM Offline
            mrdebug
            wrote on last edited by
            #5

            It' the same. The program works on Linux and Windows. Look ad my website for have a Windows version. Look at the qcserialcomport.cpp file to see how is possibile to convert string to char.

            Need programmers to hire?
            www.labcsp.com
            www.denisgottardello.it
            GMT+1
            Skype: mrdebug

            1 Reply Last reply
            0
            • JKSHJ Offline
              JKSHJ Offline
              JKSH
              Moderators
              wrote on last edited by
              #6

              Why don't you want to use a QByteArray? It's very convenient.

              @
              char expr[255];
              QString string = ...

              if (string.length() < 255) {
              QByteArray ba = string.toLocal8Bit();
              strcpy(expr, ba.constData());
              } else {
              qWarning("String is too long!");
              }
              @

              Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

              1 Reply Last reply
              0
              • K Offline
                K Offline
                koresaram777
                wrote on last edited by
                #7

                [quote author="JKSH" date="1379719254"]Why don't you want to use a QByteArray? It's very convenient.

                @
                char expr[255];
                QString string = ...

                if (string.length() < 255) {
                QByteArray ba = string.toLocal8Bit();
                strcpy(expr, ba.constData());
                } else {
                qWarning("String is too long!");
                }
                @[/quote]

                the problem is solved :) thanks everybody for help! :)

                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