Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qnetwork Manager show available SSID's



  • i am trying to use QNetwork to scan for available WLAN SSID's

    Here is my test programm that just outputs debug messages for now . The main aim was to show which Wifi networks are in range on Linux.
    I have a few issues :
    On Linux :
    Bearer Type for wlan0 and eth0 is shown as 1 (Ethernet) , i was expecting it to be 2 (WLan) for wlan0

    i was under the impression that x.name would give me the SSID's whats the correct command to get the SSiD's )

    main.cpp :

    #include "mainwindow.h"
    #include <QApplication>
    
    int main(int argc, char *argv[])
    {
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    return a.exec();
    }
    

    my mainwindow.cpp :

    #include "mainwindow.h"
    #include <QDebug>
    
    MainWindow::MainWindow(QWidget *parent)
    : QWidget(parent)
    {
    
    findTimer = new QTimer();
    findTimer->setInterval(1000);
    connect(findTimer,&QTimer::timeout,this,&MainWindow::findActiveWirelesses);
    findTimer->start();
    foundCount = 0;
    findActiveWirelesses();
    }
    
    void MainWindow::findActiveWirelesses()
    {
    QNetworkConfigurationManager ncm;
    netcfgList = ncm.allConfigurations();
    WiFisList.clear();
    for (auto &x : netcfgList)
    {
        qDebug() << "Type:" << x.bearerType() << "Name: " << x.name();
        // on Linux This returns :
        //              Type: 1 Name:  "eth0"
        //              Type: 1 Name:  "wlan0"
        
        // on Windows This returns :
        //              Type: 0 Name:  "Celluar"
        //              Type: 1 Name:  "Ethernet"
        if (x.bearerType() == QNetworkConfiguration::BearerWLAN)
        {
            //This does nothing as the bearerType stays 1 on linux and 0 or 1 on Windows
            if(x.name() == "")
                WiFisList << "Unknown(Other Network)";
            else
                WiFisList << x.name();
        }
    }
    for(int i=0; i<WiFisList.size(); i++)
    {
        bool exist = false;
        qDebug() << "Show wifi List size " << WiFisList.size();
       
    }
    }
    

    mainwindow.h :

    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H
    
    #include <QWidget>
    #include <QTimer>
    #include <QList>
    #include <QInputDialog>
    #include <QStandardItem>
    #include <QStandardItemModel>
    #include <QNetworkConfiguration>
    #include <QNetworkConfigurationManager>
    #include <QNetworkSession>
    
    class MainWindow : public QWidget
    {
    Q_OBJECT
    
    public:
    explicit MainWindow(QWidget *parent = 0);
    
    int foundCount;
    QNetworkConfiguration netcfg;
    QStringList WiFisList;
    QList<QNetworkConfiguration> netcfgList;
    
    public slots:
    void findActiveWirelesses();
    
    
    private:
    
    QTimer *findTimer;
    QStandardItemModel* listModel;
    QNetworkSession *session;
    };
    
    #endif // MAINWINDOW_H

Log in to reply