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

Scanning WiFi with Qt & Linux



  • Hi, i wold like how to scan WiFi with QT... i try with QProcess and iwlist under linux...

    void MainWindow::on_scan_clicked()
    {
        ui->scan->setText("Scanning");
    
        QString output;
        QString devices_selezionato = ui->devices->currentText();
        qDebug() << "SELECTED -> " << devices_selezionato ;
        QProcess system;
        QString command_set = "ip link set dev "+devices_selezionato+" down && sleep 1 && ip link set dev "+devices_selezionato+" up && iwlist "+devices_selezionato+" scan | grep -E 'Address|ESSID' | cut -c21- | sed 's/Address\: //g' | sed 's/ESSID\://g' ";//| sed 's/\"//g'";
        //qDebug()<<command_set;
        system.start("/bin/sh -c \""+command_set+"\"");
        system.waitForFinished();
        output = (system.readAllStandardOutput());
        output = (output + system.readAllStandardError());
        qDebug()<<"TROVO QUESTE RETI"<<output;
    
        QStringList outputlist = output.split("\n");
    
       // ui->lista_reti->setStyleSheet("overflow: auto; color:red;");
    
        int i = 0;
        QString col0;
        QString col1;
    
        foreach(QString value, outputlist)
        {
            i++;
            //ui->lista_reti->setText(ui->lista_reti->text() + value.replace("\n", "").replace("\"", "") + "\n");
            QTreeWidgetItem * item = new QTreeWidgetItem();
            item->setTextAlignment(0,Qt::AlignVCenter);
            item->setTextAlignment(1,Qt::AlignHCenter);
    
    
            if(i%2) { col0 = value; }
            else { col1 = value;}
            if(! col0.isEmpty() && !col1.isEmpty())
            { item->setText(0,col0); item->setText(1,col1); ui->treeWidgetWiFis->addTopLevelItem(item); col0="";col1=""; }
    
            qDebug() << value;
        }
    }
    

    Exists a method for scan WiFi directly with QT ?

    Thanks Francesco


  • Lifetime Qt Champion

    Hi,

    If you are thinking about a replacement of iwlist, there's none directly as it is outside the scope of Qt.



  • so I can not scan WiFi with Qt?


  • Lifetime Qt Champion

    The way you did it using QPorces seems good it this point.



  • thanks ;)....
    Francesco


  • Banned

    This post is deleted!

Log in to reply