QNetworkConfigurationManager::allConfigurations() doesn't list WLAN - c++

Running under Windows 10, tested with two different Systems:
When i run QNetworkConfigurationManager::allConfigurations() I don't get any WLAN configuration, even if I'm connected actively to a Wifi Network.
Header:
public:
NetworkManager(QObject* parent = 0);
private slots:
void onNetworkConfigUpdate();
private:
QNetworkConfiguration cfg;
QList<QNetworkConfiguration> netcfgList;
QNetworkConfigurationManager ncm;
.cpp
NetworkManager::NetworkManager(QObject* parent) : QObject(parent) {
ncm.updateConfigurations();
connect(&ncm, SIGNAL(updateCompleted()), this, SLOT(onNetworkConfigUpdate()));
}
void NetworkManager::onNetworkConfigUpdate() {
netcfgList = ncm.allConfigurations();
for (auto& x : netcfgList) {
if (x.bearerType() == QNetworkConfiguration::BearerWLAN) {
qDebug() << "Wifi found: " << x.name();
} else {
qDebug() << "Something else: " << x.bearerType() << " - name: " << x.name();
}
}
}
Output:
Something else: 0 - name: "Teredo Tunneling Pseudo-Interface"
Something else: 1 - name: "Ethernet"
Something else: 1 - name: "VirtualBox Host-Only Network"
I'm running on Windows 10; Qt 5.9.4 with MSVC2015
I checked with an Intel Wireless Card and an external USB Wifi-Stick. Why is it not showing any WLAN?

I had the same problem. To me was caused by a missing bearer plugin DLL.
To sort this out, I had to copy the QT "plugins/bearer" folder (containing qgenericbearer.dll and qnativewifibearer.dll) in my application root folder.
Like this:
ApplicationFolder/
Application.exe
...
Qt5Network.dll
bearer/
qgenericbearer.dll
qnativewifibearer.dll

Related

Cannot connect to the device with QSerialPort

I develop Qt application in C++ under manjaro linux. The goal is to connect with a qC (Nucleo-L476RG Board) and receive data from accelerometer. App can find device on /dev/ttyACM0, but when i try to connect it fails with error "QSerialPort::DeviceNotFoundError". Checking errorString() gives "No such file or directory", but it still can find it in /dev.
I'm in the right group to read the file:
[1]: https://i.stack.imgur.com/CG1yZ.png
I use Qt v.6.2.4, but have build the code with Qt v.5.15.3. I tried to run another person's app that does the same and works under ubuntu, but it didn't work.
Here is my code with the searching and connecting methods. Method addToLogs() just prints logs in textEdit.
void MainWindow::addToLogs(QString message)
{
QString currDateTime = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss");
ui->textEditLogs->append(currDateTime + "\t" + message);
}
void MainWindow::on_pushButtonSearch_clicked()
{
ui->comboBoxDevices->clear();
this->addToLogs("Szukam urządzeń...");
QList<QSerialPortInfo> devices;
devices = QSerialPortInfo::availablePorts();
if(devices.count() > 0)
{
for(int i=0; i<devices.count(); i++)
{
this->addToLogs(devices.at(i).portName());// + " " + devices.at(i).description());
//ui->comboBoxDevices->addItem(devices.at(i).systemLocation());//portName());
ui->comboBoxDevices->addItem(devices.at(i).portName());
}
}
}
void MainWindow::on_pushButtonConnect_clicked()
{
if(ui->comboBoxDevices->count() == 0)
{
this->addToLogs("Nie wykryto żadnych urządzeń!");
return;
}
if(this->device->isOpen())
{
this->addToLogs("Port jest już otwarty!");
return;
}
QString portName = ui->comboBoxDevices->currentText();
//this->device->setPortName(portName);
this->device->setPortName("/dev/ttyACM0");
qDebug() << this->device->portName();
if(device->open(QSerialPort::ReadWrite))
{
this->device->setBaudRate(QSerialPort::Baud9600);
this->device->setParity(QSerialPort::NoParity);
this->device->setDataBits(QSerialPort::Data8);
this->device->setStopBits(QSerialPort::OneStop);
this->device->setFlowControl(QSerialPort::NoFlowControl);
this->addToLogs("Połączono z urządzeniem " + portName);
}
else
{
this->addToLogs("Otwarcie portu szeregowego się nie powiodło!");
this->addToLogs(device->errorString());
qDebug() << this->device->error();
}
}
I will be thankful for help, cause i've benn sitting on it for last 2 or 3 weeks and nothing works.

Can't access .ONION websites using QT C++, How To do it?

Can someone can tell me why my code does not work? I made a program using QT C++ to route through TOR, I can access normal websites and I have a different public IP but I can't access .ONION websites, I get no response and/or Host not found.
EDIT: AFTER FURTHER INSPECTION I THINK THE PROBLEM IS THAT I NEED TO RESOLVE THE DNS FOR THE .ONION ADDRESS, HOW CAN I DO THAT?
tester::tester(QObject *parent) :
QObject(parent)
{
}
QTcpSocket socket ;
void tester::GetUrl()
{
QNetworkProxy proxy;
proxy.setType(QNetworkProxy::DefaultProxy);
proxy.setHostName("127.0.0.1");
proxy.setPort(9050);
proxy.setCapabilities(QNetworkProxy::HostNameLookupCapability | proxy.capabilities());
QNetworkProxy::setApplicationProxy(proxy);
qDebug()<<"Connecting";
QNetworkAccessManager *manager = new QNetworkAccessManager(this);
manager->setProxy(proxy);
connect(manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyFinished(QNetworkReply*)));
//manager->get(QNetworkRequest(QUrl("http://www.whatsmyip.org"))); //works
//test access to random .onion website
manager->get(QNetworkRequest(QUrl("http://blackma6xtzkajcy2eahws4q65ayhnsa6kghu6oa6sci2ul47fq66jqd.onion/products.php")));
//test access to random .onion website via socket
socket.setProxy(proxy);
socket.connectToHost("http://blackma6xtzkajcy2eahws4q65ayhnsa6kghu6oa6sci2ul47fq66jqd.onion/products.php",9051);
qDebug() << "\nTCP SOCKET Response...\n";
if(!socket.waitForConnected(5000))
qDebug() << "Error: " + socket.errorString() +"\n";
}
void tester::replyFinished(QNetworkReply* Reply)
{
qDebug() << "Response...\n";
if (Reply->isOpen())
{
qDebug()<<Reply->read((5000));
Reply->close();
}
qDebug() << "\nTCP SOCKET Response...\n";
if(!socket.waitForConnected(5000))
qDebug() << "Error: " + socket.errorString() +"\n";
}

network manager dbus interface calls for wireless doesnt work on raspbian

I have the following code to retrieve access points information using NetworkManager dbus api:
//---------------------------------------------------------------------------------
QDBusInterface dbus_iface("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager/Devices/2", // path (might be different in other systems)
"org.freedesktop.NetworkManager.Device.Wireless",
bus);
QDBusMessage query = dbus_iface.call("GetAllAccessPoints");
qDebug() << query;
if(query.type() == QDBusMessage::ReplyMessage) {
QDBusArgument arg = query.arguments().at(0).value<QDBusArgument>();
arg.beginArray();
while(!arg.atEnd()) {
QString element = qdbus_cast<QString>(arg);
netList->append(element);
showAccessPointProperties(element);
}
arg.endArray();
} else {
qDebug() << " dbus error: " << query.errorName();
}
This code works on desktop linux (ubuntu 18.04).
But in raspbian (buster, raspberry pi 3 B/B+) this code doesn't work! The problem is that this call :
dbus_iface.call("GetAllAccessPoints");
returns empty reply.
Is it anything different on how to use NM dbus interface in raspbian and ubuntu?

Permission error on opening USB dongle using QSerialPort

I'm trying to access a USB dongle (which has SIM card in it) using QSerialPort.
The dongle is successful identified but when trying to open it I get permission error. The description of the error message from Qt documentation states that this could be that the device is being accessed by another service or the user has no permission. I attempted to disconnect the dongle and connect it again with the same results. How can I solve this. I'm on Ubuntu 16.04 64bit using Qt 5.7. The code I'm running is as below.
#include <QApplication>
#include <QString>
#include <QDebug>
#include <QList>
#include <QSerialPortInfo>
#include <QSerialPort>
#include <QDebug>
int main(int argc, char *argv[])
{
QList<QSerialPortInfo> ports = QSerialPortInfo::availablePorts();
QSerialPort *port = nullptr;
QString portName;
int counter = 0;
while(counter < ports.size())
{
portName = ports[counter].portName();
quint16 productId = ports[counter].productIdentifier();
quint16 vendorId = ports[counter].vendorIdentifier();
QString manufacturerName = ports[counter].manufacturer();
qDebug() << "Port Name: " << portName;
qDebug() << "Product ID:" << productId;
qDebug() << "Vendor Id: " << vendorId;
qDebug() << "Manufacturer: " << manufacturerName;
++counter;
if(manufacturerName.contains("Huawei", Qt::CaseInsensitive))
{
qDebug() << "found!" << " name: " << portName;
port = new QSerialPort(portName);
break;
}
}
//Write and send the SMS
bool opened = port->open(QIODevice::ReadWrite);
if(!opened)
{
qDebug() << "Error: " << port->error();
}
// some more code here
return 0;
}
The output is as below:
Port Name: "ttyS4"
Product ID: 11799
Vendor Id: 32902
Manufacturer: ""
Port Name: "ttyUSB0"
Product ID: 5382
Vendor Id: 4817
Manufacturer: "HUAWEI"
found! name: "ttyUSB0"
Error: QSerialPort::SerialPortError(PermissionError)
Serial devices are usually located in the /dev/ folder and is owned by root. It is likely that you need root access to open the device.
For example, with your dongle plugged in, you could get the permissions on the device with the following command:
ls -l /dev/ttyUSB0
Does it work if you run the program with 'sudo' or as root?
In a terminal, try running your program prefixed with the 'sudo' command. This will elevate your privileges to the root level:
sudo ./my_program
Open (as root) /etc/udev/rules.d/90-my-usb-dongle.rules and write:
SUBSYSTEM=="usb", ATTR{idVendor}=="12d1", ATTR{idProduct}=="1506", MODE="0666"
This tells linux to set R/W permissions for all to your device (note that idVendor and idProduct are hexadecimal).
Now reload udev rules:
# udevadm control --reload-rules
and check again

Connecting to MS SQLServer from Qt Linux application

I'm trying to connect to a MS SQL Server on a remote box using QODBC in my Qt Linux application.
Here's what I have done so far:
Added QT += SQL in the .pro file.
Tested some db functions:
QStringList drivers = QSqlDatabase::drivers();
qDebug() << "Drivers: " ;
foreach(QString driver, drivers) {
qDebug() << ":: " << driver;
}
qDebug() << "Connection Names: ";
QStringList connames = QSqlDatabase::connectionNames();
foreach(QString conname, connames) {
qDebug() << ":: " << conname;
}
qDebug() << "---";
these both work, though connectionNames() is empty at this stage.
I have tried to added a database:
QString serverName = "server1";
QString dbName = "abc123";
QSqlDatabase db = QSqlDatabase::addDatabase("QODBC", "MyFirst");
db.setHostName(serverName);
QString myCon = QString("DRIVER={SQL Native Client};SERVER=%1;DATABASE=%2;Trusted_Connection = Yes").arg(serverName).arg(dbName);
db.setDatabaseName(myCon);
If I now list the connections, "MyFirst" is in the list.
Tried to open the database:
bool ok = db.open();
qDebug() << "OK: " << ok;
if (!ok) {
qDebug() << "error: " << db.lastError().text();
}
The db.open() fails with the following message:
"[unixODBC][Driver Manager]Can't open lib 'SQL Native Client' : file not found QODBC3: Unable to connect"
My questions are:
I picked up the connection string from a forum post, I figured it was as good a place to start as any, but what exactly should be in there? Where does "SQL NAtive Client" come from? What do I need to do to setup my Qt / Linux box to be able to connect to a remote MS SQL Server?
Sounds like you need to install the SQL Server ODBC Driver.
An explanation for how to do that is here:
https://technet.microsoft.com/en-us/library/hh568454(v=sql.110).aspx
In addition you need to refer to it by the correct name, which is "ODBC Driver 11 for SQL Server"