Cannot connect to wifi name has character represented
Solved
General and Desktop
-
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.
-
all characters in this link: https://www.austincc.edu/rickster/COSC1320/handouts/escchar.htm
-
@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++.
-
@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.