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. Cannot connect to wifi name has character represented
QtWS25 Last Chance

Cannot connect to wifi name has character represented

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 474 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.
  • hooanghiepH Offline
    hooanghiepH Offline
    hooanghiep
    wrote on last edited by
    #1

    i am trying to connect wifi by using nmcli. When wifi name has character represented then i got error:
    Syntax error: Unterminated quoted string
    here is my code:

    void WifiThread::connectWifi(QString strName, QString strPassword) 
    {
        QString strTmp = QString("nmcli --wait 20 device wifi connect \"%1\" password \"%2\" 2>&1").arg(strName, strPassword);
            QByteArray ba = strTmp.toUtf8();
            const char *pCommand = ba.data();
            system(pCommand);
    }
    

    thank you so much for your help.

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

      Hi,

      What characters are causing trouble ?
      Why not use QProcess ?

      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
      2
      • hooanghiepH Offline
        hooanghiepH Offline
        hooanghiep
        wrote on last edited by
        #3

        all characters in this link: https://www.austincc.edu/rickster/COSC1320/handouts/escchar.htm

        jsulmJ 1 Reply Last reply
        0
        • hooanghiepH hooanghiep

          all characters in this link: https://www.austincc.edu/rickster/COSC1320/handouts/escchar.htm

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

          @hooanghiep You need to escape such characters, like

          nmcli --wait 20 device wifi connect \"abcd\\\"efg\" password ...
          

          First 2 backslashes are there to put a backslash into your string, third one is to escape " in C++.

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

          hooanghiepH 1 Reply Last reply
          1
          • jsulmJ jsulm

            @hooanghiep You need to escape such characters, like

            nmcli --wait 20 device wifi connect \"abcd\\\"efg\" password ...
            

            First 2 backslashes are there to put a backslash into your string, third one is to escape " in C++.

            hooanghiepH Offline
            hooanghiepH Offline
            hooanghiep
            wrote on last edited by hooanghiep
            #5

            @jsulm how about these characters: "\", " ' ", "?"
            thanks for your answer. :)

            jsulmJ 1 Reply Last reply
            0
            • hooanghiepH hooanghiep

              @jsulm how about these characters: "\", " ' ", "?"
              thanks for your answer. :)

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

              @hooanghiep said in Cannot connect to wifi name has character represented:

              how about these characters

              It's same for all characters which needs to be escaped in a shell.

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

              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