I am writing a Qt based application on a ARM linux device. I want to be able to create wifi functionality in the most efficient way. Currently I am using QProcess to run a script that modifies the network block of wpa_supplicant.conf and kicks off the wlan0 interface to connect to an access point. This is what the sh script looks like:

sed -i 's: ssid=.*: ssid="Name":' /etc/wpa_supplicant.conf
sed -i 's: psk=.*: psk="Password":' /etc/wpa_supplicant.conf
ifdown wlan0
ifup wlan0

And to scan networks I run a separate QProcess which runs the command:

iw wlan0 scan | grep SSID

I am new to Qt and embedded development so I want to ask a few questions. Is there a better way to run scripts from Qt other than using QProcess that's more efficient? How costly is using too many QProcesses? I have also came across wpa_cli and I would like to use it but I don't know how to interface with it through Qt or any C++ application. If anyone could give me guidance to a better way of handling scanning and connecting to wifi (or in general the best way to run commands in linux from Qt) I would appreciate it. Thanks

  • Have a look at the wpa_supplicant API (e.g. source code of wpa_cli or wpa_gui)), then you neither need to change /etc/wpa_supplicant.conf, nor do you need to run iw wlan0 scan. – dirkt Aug 30 '19 at 15:57

QProcess is by far the most direct method to run an external program. I use it frequently and parse the output of the command in linux.

Yes, there is another method to connect to networks directly using QNetwork which is easy also and not difficult

See this link for scanning networks using QT and QNetwork https://stackoverflow.com/questions/45486924/qt-scanning-wi-fi-by-qnetworkaccessmanager and this link https://github.com/abdularis/Wifi-Client-Scanner and this one https://github.com/nlharri/WifiScannerLinux

In case you need to connect to wpa supplicant, there is a nice program that shows you how to do it using qt https://github.com/loh-tar/wpa-cute

to learn more about WPA Supplicant, please see this https://wiki.archlinux.org/index.php/WPA_supplicant

finally please give a thumb

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.