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. how to set ' " ' in QString
QtWS25 Last Chance

how to set ' " ' in QString

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 1.9k Views
  • 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.
  • V Offline
    V Offline
    victor wang
    wrote on last edited by victor wang
    #1

    Hi All,
    I'm using qt5.5 on my computer.
    And I try to set a command like bellow.

    /usr/sbin/wpa_cli -i wlan0 set_network psk '"iPhone"'
    

    So I write this way in my program.

    QString wifi = "iPhone";
    QString command = "/usr/sbin/wpa_cli -i wlan0 set_network psk '\""+wifi+"\"'";
    QString test ="hello";
    qDebug()<<command;
    

    But i will get the output like bellow.

    /usr/sbin/wpa_cli -i wlan0 set_network psk '\"iPhone\"'
    

    Is that ' \ ' have to put behind the ' " '?
    Thanks in Advanced!

    jsulmJ 1 Reply Last reply
    0
    • V victor wang

      Hi All,
      I'm using qt5.5 on my computer.
      And I try to set a command like bellow.

      /usr/sbin/wpa_cli -i wlan0 set_network psk '"iPhone"'
      

      So I write this way in my program.

      QString wifi = "iPhone";
      QString command = "/usr/sbin/wpa_cli -i wlan0 set_network psk '\""+wifi+"\"'";
      QString test ="hello";
      qDebug()<<command;
      

      But i will get the output like bellow.

      /usr/sbin/wpa_cli -i wlan0 set_network psk '\"iPhone\"'
      

      Is that ' \ ' have to put behind the ' " '?
      Thanks in Advanced!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @victor-wang Just print out your string with

      std::cout << command;
      

      qDebug is for debugging and prints out the strings like you see them in the code.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      V 1 Reply Last reply
      3
      • jsulmJ jsulm

        @victor-wang Just print out your string with

        std::cout << command;
        

        qDebug is for debugging and prints out the strings like you see them in the code.

        V Offline
        V Offline
        victor wang
        wrote on last edited by
        #3

        @jsulm
        It will give me this error when I compile.

         error: 'cout' is not a member of 'std'
         std::cout << command;
         ^
        
        jsulmJ D 2 Replies Last reply
        0
        • V victor wang

          @jsulm
          It will give me this error when I compile.

           error: 'cout' is not a member of 'std'
           std::cout << command;
           ^
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @victor-wang Well, there is documentation you could read to solve the problem (note: cout is part of C++ standard library): http://en.cppreference.com/w/cpp/io/cout ...
          You need to include <iostream> header file:

          #include <iostream>
          

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          V 1 Reply Last reply
          2
          • jsulmJ jsulm

            @victor-wang Well, there is documentation you could read to solve the problem (note: cout is part of C++ standard library): http://en.cppreference.com/w/cpp/io/cout ...
            You need to include <iostream> header file:

            #include <iostream>
            
            V Offline
            V Offline
            victor wang
            wrote on last edited by
            #5

            @jsulm
            Thanks I had read the document and it work great!

            1 Reply Last reply
            0
            • V victor wang

              @jsulm
              It will give me this error when I compile.

               error: 'cout' is not a member of 'std'
               std::cout << command;
               ^
              
              D Offline
              D Offline
              Devopia53
              wrote on last edited by
              #6

              @victor-wang

              To added to @jsulm, you can use qPrintable() instead of std::cout.

              like this:

              qDebug() << qPrintable(command);
              

              or

              qDebug() << command.toLocal8Bit().constData();
              
              V 1 Reply Last reply
              5
              • Chris KawaC Online
                Chris KawaC Online
                Chris Kawa
                Lifetime Qt Champion
                wrote on last edited by
                #7

                or

                qDebug().noquote() << command;
                
                V 1 Reply Last reply
                6
                • D Devopia53

                  @victor-wang

                  To added to @jsulm, you can use qPrintable() instead of std::cout.

                  like this:

                  qDebug() << qPrintable(command);
                  

                  or

                  qDebug() << command.toLocal8Bit().constData();
                  
                  V Offline
                  V Offline
                  victor wang
                  wrote on last edited by
                  #8

                  @Devopia53
                  Thanks! I think this is more familiar to me.

                  1 Reply Last reply
                  0
                  • Chris KawaC Chris Kawa

                    or

                    qDebug().noquote() << command;
                    
                    V Offline
                    V Offline
                    victor wang
                    wrote on last edited by
                    #9

                    @Chris-Kawa
                    Thanks for the reply.
                    I can do this too!

                    1 Reply Last reply
                    1

                    • Login

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