Port scanning is not working properly
-
Hi,
I typed the command below on my Windows computer and when I ran it, no output was produced. I typed the command below on my Windows computer and when I ran it, no output was produced. I wonder why this is happening and what is the solution. Why can't I print or see the ports? I uninstalled and reinstalled the application (QT6) but not the solution.The code used to print all ports on Linux devices and Windows, and if something was connected to the port, it would also print other information. Now it only sees the FTDI I connected.
I installed stm32cubeide on my system, is there a chance that it will break the working of QT?
code:
#include <QCoreApplication> #include <QSerialPort> #include <QSerialPortInfo> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); foreach (const QSerialPortInfo &portInfo, QSerialPortInfo::availablePorts()) { qDebug() << "-----------------------------------------------------"; qDebug() << "Port Name: " << portInfo.portName(); qDebug() << "System Location: " << portInfo.systemLocation(); qDebug() << "Description: " << portInfo.description(); qDebug() << "Manufacturer: " << portInfo.manufacturer(); qDebug() << "Serial Number: " << portInfo.serialNumber(); } return a.exec(); } -
Hi, the code is correct and there isn't a problem on Qt related to serial ports.
In order to have a comport available in Qt you should verify if it is correctly configured in Windows, please have a look at the Windows devices list and check that the driver is configured correctly.
You can't know what it is attached to a comport without to check it by protocol, for example if you want to know if there is a modem plugged in you should use the AT commands in all com ports to search for a modem. You only can know if a comport in already open or not.
The vendor is relative to the usb adapter but the device could be different.
If you want to use a usb device without to configured it you could use libusb. -
Hi,
I typed the command below on my Windows computer and when I ran it, no output was produced. I typed the command below on my Windows computer and when I ran it, no output was produced. I wonder why this is happening and what is the solution. Why can't I print or see the ports? I uninstalled and reinstalled the application (QT6) but not the solution.The code used to print all ports on Linux devices and Windows, and if something was connected to the port, it would also print other information. Now it only sees the FTDI I connected.
I installed stm32cubeide on my system, is there a chance that it will break the working of QT?
code:
#include <QCoreApplication> #include <QSerialPort> #include <QSerialPortInfo> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); foreach (const QSerialPortInfo &portInfo, QSerialPortInfo::availablePorts()) { qDebug() << "-----------------------------------------------------"; qDebug() << "Port Name: " << portInfo.portName(); qDebug() << "System Location: " << portInfo.systemLocation(); qDebug() << "Description: " << portInfo.description(); qDebug() << "Manufacturer: " << portInfo.manufacturer(); qDebug() << "Serial Number: " << portInfo.serialNumber(); } return a.exec(); }@serkan_tr said in Port scanning is not working properly:
Why can't I print or see the ports?
Because QSerialPortInfo::availablePorts() returns an empty list.
Does your machine have working serial ports? -
one interesting thing you should do : print to console the size of the list
QList <QSerialPortInfo> listPorts = QSerialPortInfo::availablePorts() ; qDebug() << "Serial ports count : " << listPorts.size() ;So that you get an explicit indication of an empty list.
-
@serkan_tr said in Port scanning is not working properly:
Why can't I print or see the ports?
Because QSerialPortInfo::availablePorts() returns an empty list.
Does your machine have working serial ports?@jsulm In normal use, it showed all "com" ports whether something was plugged in or not. When I deploy the code and run it on a different computer, it gives the correct output.
It turned out right:

I use my computer as a dual operating system and this code works correctly on the Linux side. It does not work correctly on the Windows side on the computer I built it on. When I run the executable on a different computer, it works correctly.
Make sure the code is correct. The only problem is that there seems to be a situation on my Windows computer that prevents this from happening. This code was working correctly when I first wrote it. But the last time I tried it, it stopped working properly.
-
one interesting thing you should do : print to console the size of the list
QList <QSerialPortInfo> listPorts = QSerialPortInfo::availablePorts() ; qDebug() << "Serial ports count : " << listPorts.size() ;So that you get an explicit indication of an empty list.
@ankou29666 Make sure the code is correct. The only problem is that there seems to be a situation on my Windows computer that prevents this from happening. This code was working correctly when I first wrote it. But the last time I tried it, it stopped working properly.
-
Hi, the code is correct and there isn't a problem on Qt related to serial ports.
In order to have a comport available in Qt you should verify if it is correctly configured in Windows, please have a look at the Windows devices list and check that the driver is configured correctly.
You can't know what it is attached to a comport without to check it by protocol, for example if you want to know if there is a modem plugged in you should use the AT commands in all com ports to search for a modem. You only can know if a comport in already open or not.
The vendor is relative to the usb adapter but the device could be different.
If you want to use a usb device without to configured it you could use libusb. -
S serkan_tr has marked this topic as solved on