Important: Please read the Qt Code of Conduct -

QtSerialPort with no libudev

  • I am using QtSerialPort with Qt 4.8.6. The target is an embedded montavista system. I read in another forum that it is possible to build the QtSerialPort library with no udev requirements. Is this true? If so, how do I do it?

  • Sorry I neglected to add the link.

  • Qt Champions 2020

    Checking of libudev existence (libudev-dev) does automatically when you try to open the file from the root directory of the QtSerialPort sources. In this case triggered the packagesExist script in "serialport-lib.pri" file:

    unix {
    packagesExist(libudev) {
    CONFIG += link_pkgconfig
    PKGCONFIG += libudev

    If your target's rootfs has libudev, then the LINK_LIBUDEV macro will be defined. In this case your QtSerialPort will be explicitly linked with the libudev library. Otherwise, your QtSerialPort will be trying to search and resolve the libudev in runtime.

    So, in any case if your target contains the, then QtSerialPort always will use libudev (has no matter, is triggered the LINK_LIBUDEV macro or not in compile time).

    So, if the libudev doesn't contains physically on your target and QtSerialPort was compiled without LINK_LIBUDEV macro, then will be used SysFs in runtime. Otherwise your application even does not startup, if the LINK_LIBUDEV macro was defined in compile time.

    Thus, it is enough to comments out the code "/* unix {...} */" (see above snippet) in the serialport-lib.pri file and to rebuild QtSerialPort. In this case QtSerialPort always will try to resolve libudev in runtime and if no libudev present then SysFs will be used.

    In case if you want even do not resolve libudev in runtime, then in addition you should to comments out the availablePortsByUdev() function in "qserialportinfo_unix.cpp" file:

    QList<QSerialPortInfo> QSerialPortInfo::availablePorts()
    bool ok;

    QList<QSerialPortInfo> serialPortInfoList; /// << COMMENTS OUT THIS

    #ifdef Q_OS_LINUX
    /// if (!ok) <<< AND COMMENTS OUT THIS
    serialPortInfoList = availablePortsBySysfs(ok);

    if (!ok)
        serialPortInfoList = availablePortsByFiltersOfDevices(ok);
    return serialPortInfoList;


    and to rebuild QtSerialPort.

Log in to reply