#include "networkscanner.h" #include #include #include #include #include #include std::string exec(const char* cmd) { std::array buffer; std::string result; std::unique_ptr pipe(popen(cmd, "r"), pclose); if (!pipe) { throw std::runtime_error("popen() failed!"); } while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { result += buffer.data(); } return result; } QList NetworkScanner::scanForNetworks() { std::cout << "Called the C++ Network scanner class" << std::endl; QList networks; Network example1 = Network("Gita 2.4Ghz"); networks.append(example1); std::string result = exec("nmcli -t -f ssid dev wifi"); std::vector ssids; std::istringstream iss(result); std::string line; while (std::getline(iss, line)) { ssids.push_back(line); } for (const std::string &ssid : ssids) { Network newNetwork = Network(ssid.c_str()); networks.append(newNetwork); } return networks; }