Important: Please read the Qt Code of Conduct -

Problems when adding serialport module in Qt project

  • @douglas
    @aha_1980 told you need to install the packages individualy.

    sudo apt-get install libqt5serialport5
    sudo apt-get install libqt5serialport5-dev

  • @KillerSmath I installed those packages via Software Center. Perhaps have I to uninstall them and re-install via apt-get?
    Could it be the reason for the "unknown module" error?

  • Lifetime Qt Champion

    Silly question: are you sure you are using Qt 5 and not Qt 4 for your project ?

  • @SGaist Yes, the Help menu from Qt Creator reports:
    In fact, I read that serialport module was not included in Qt4, but it seems I am using Qt5, this is the reason why I can't understand that build error..

  • Lifetime Qt Champion

    That's just the information about Qt Creator.

    You have to check the Kit you are using to build your application and which version of Qt it is using.

  • @douglas
    If nothing works, you can try to manage the packages from MaintenanceTool of QtCreator

      1. <Qt Folder>/MaintenanceTool
      1. Add or remove Components
      1. Expand your Qt version
      1. Expand Source Components
      1. Select the Qt Source Package
      1. Next, Install

  • @SGaist how can I make sure of the Qt version I am using in my project?

  • This post is deleted!

  • Moderators

    In QtCreator go to Tools -> Options -> build & run and check your kits


    In sidebar under the "Projects tab" you can select one of your installed kits:

  • @J.Hilk My environment is a bit different; I can't find informations about the version..

  • Moderators

    from what one can see, it at least seems to be a version of Qt5, for more information press the "Manage kits" button

  • @J.Hilk The Manage Kit button shows the settings reported below, in which I can't find any information regarding the Qt version in use:

    If from terminal I write

    $ qmake --version

    I obtain the following:

    qmake: could not exec '/usr/lib/x86_64-linux-gnu/qt4/bin/qmake': No such file or directory

    Is it relevant the "qt4" shown in that prompt?

  • Moderators

    well, there we have your problem


    you have no QtLibary selected to your kit. Se if you can actually select a QtVersion from that dropdown menu. If you can't than you need to install an actual qt version.

    I would recommend the online installer from the Webside.

  • @J.Hilk Thanks, I added the version as shown below:
    Now, since I should have Qt5, I added the serialport support in my .pro file, but the "unknow module" error still remains. I saw another thing that seems not so clear to me: I run Qt Creator from linux terminal, and when I open my project the terminal shows the following lines, marked in red, in which appears Qt4. Can this be related to the serialport module error?
    thank you again.

  • Lifetime Qt Champion

    @douglas Above you said you installed Qt 5.6, now you selected Qt 5.7.1
    Which Qt version do you really want to use and did you install QtSearialPort for Qt 5.7.1?

  • @jsulm when I spoke about Qt 5.6 I was referring to the "About Qt Creator" window shown above. Now I selected Qt 5.7.1 as the version for my kit. But the serialport module isn't recognized yet. What I should do to correctly install QtSerialPort for my actual version?

  • @douglas could it be possible that you start from scratch with a clean installation of Qt, ideally latest version 5.11? you may try in a virtual machine just in case.

  • Lifetime Qt Champion

    Is it me or are you trying to build your project for an embedded system ?
    I see that you are trying to use an arm compiler, did you cross-compile Qt for your device ?

  • @SGaist Yes, my target device runs Linux Yocto. Can this affect the serialport module I am trying to install?

  • Lifetime Qt Champion

    Sur it does, you are trying to install the desktop version of the driver and then, use it to do cross-compilation.

  • @SGaist I see. So, if I need to cross-compile, which steps should I follow in order to use the serialport in my project?
    Are there different libraries or drivers I need to install on my host PC?
    The target linux embedded device runs Linux Yocto.

  • Lifetime Qt Champion

    @douglas You need Qt (together with Qt Searial Port) cross compiled for your device

  • @jsulm I already set up the project in order to cross-compile for my target: in fact, I have already managed to run my application on the target device. The problem is the serial port module: I did not succeeded in including it into my project. Are there any particular hints to follow in the case of cross-compilation?
    Thank you!

  • Lifetime Qt Champion

    @douglas Did you cross compile Qt serial port module?

  • Moderators

    How did you cross-compile for your target device?

    I would asume you cloned the qt-sources from git or something similar. However did you crosscompile the whole Framework or only part of it? For any Qt-Program to run you'll need only QtBase, however serialport is a plugin and needs to be compiled seperately.

  • @J.Hilk Where can I found the procedure to cross-compile the serial port module?
    Thank you.

  • Moderators

    @douglas like you did the other modules

    git clone git://<qt-module>.git -b <qt-version>
    cd <qt-module>
    make install

  • @douglas if you could please show us

    How did you cross-compile for your target device?

    It may help understanding your issue

  • @Pablo-J.-Rogina , after the Qt Creator installation, I followed the indication from 2.1 to 2.7 chapter here:
    in which, as far as I see, the environment is configured to cross-compile for my target device.
    Now, I am able to create a simple GUI application and run it on my target device, but I can't add the serialport component (in order to manage a RS485 communication) in my project.
    Unfortunatelly, I'm a beginner in this matter!
    Thanks a lot!

  • @douglas said in Problems when adding serialport module in Qt project:

    Now, I am able to create a simple GUI application and run it on my target device

    Ok, that's a great step. Reading briefly the link you posted to that wiki page, I assume you setup your environment in a Linux PC and using Qt Creator there, you built that simple GUI app that Qt Creator deployed and run in your device.

    If that's correct, I'd try the following:

    1. from command line in let's say /home/douglas/projects do
    cd /home/douglas/projects
    git clone git:// -b 5.9
    cd qtserialport

    so you should now have a folder /home/douglas/projects/qtserialport will sources for Qt serial port module release 5.9 (the Qt release should match what you have in your dev environment/device, you didn't stated it so far).
    2. run commands:

    make install

    once build and install finishes, you should have the .so shared library and headers into the proper location under your host PC (I couldn't figure out the proper location from the wiki page). But look for something like this (version shuold be the one you cloned...):




    if you succeed here, then you should be able to create a project file (.pro) for your application and add the serial port modulie like this:

    QT += serialport

    and the magic will flow.

  • @Pablo-J.-Rogina Thanks a lot for your post, I'll now begin to put it into practice. I have just one doubt: if I run:

    qmake --version

    I obtain:

    QMake version 2.01a
    Using Qt version 4.8.7 in /usr/lib/x86_64-linux-gnu

    So, if I'm not wrong, the installed version of Qt is the 4.8.7 (quite old). When you stated, in your #1 step, "git clone git:// -b 5.9" were you assuming my Qt version was 5.9? In other words, the serialport version and the installed qt version should be the same?
    If so, how can I upgrade from my actual Qt version to the latest one?
    Thanks a lot!

  • Lifetime Qt Champion


    you can have multiple Qt versions installed, so please check carefully which one you use.

    For the qmakes that are not in PATH, you have to specify the full path, e.g. /opt/Qt/5.9.0/bin/qmake


  • @aha_1980 how I can upgrade to the latest Qt version and set it as default in my project? After this I will be sure to use the Qt version 5.9 and I will apply the steps suggested by @Pablo-J-Rogina
    Thank you!

  • Lifetime Qt Champion


    First you should find out which Qt versions you have on your computer. Qt 4.8.7 is surely from Ubuntu and is a native Qt - you build programs that run on your computer. What you want, is a cross Qt, to run programs on your embedded device.

    As you said you have already done this, you surely have a second Qt version (I cannot tell you which one it is). And this Qt version has a qmake which you need to call to compile Qt programs against this Qt library.


  • @aha_1980 Thanks. In Qt Creator I set Qt 5.7.1 in the "Qt Version" for the selected kit for my project. Now I can add the serialport module in my .pro file and build the app, but when I try to run it on my target device, the application does not start and the following error appears:

    error while loading shared libraries: cannot open shared object file: No such file or directory

    Is it related to the serialport module that is not cross compiled or have I to install some dependencies on the target device itself?
    Thank you!

  • Lifetime Qt Champion

    @douglas said in Problems when adding serialport module in Qt project:

    Is it related to the serialport module that is not cross compiled or have I to install some dependencies on the target device itself?

    You're already on the right track. You need to cross-compile QtSerialPort for your embedded device, and then you need to deploy (copy over) these libraries to the device, because your final app is also running there.

  • @aha_1980 Ok,thanks! I just did the following on my host PC:

    $ git clone git://
    $ mkdir qtserialport-build
    $ cd qtserialport-build
    $ qmake ../qtserialport/

    but the last command (qmake) gives the following:

    Project MESSAGE: Cannot build current QtSerialPort sources with Qt version 4.8.7.
    Project ERROR: Use at least Qt 5.0.0 or try to download QtSerialPort for Qt4.

    It is clear that I need to use a newer qmake, perhaps the default one is an older version. How can I run that command with a qmake version 5? Where should it be located? Or how can I "change the default one"?
    Thanks for your patience.

  • @aha_1980 Done, I found the qmake for version 5 and run the qmake command.
    Now, when I run the

    make install

    this error appears:

    fatal error: qdeadlinetimer.h: File o directory non esistente
    compilation terminated.

    Which can be the solution?

  • Lifetime Qt Champion

    @douglas you are tryin to compile a new QSerialPort against an older Qt.

    Add a git checkout -b v5.7.1 directly after the git clone command and rebuild.

  • @aha_1980 I add "git checkout -b v5.7.1" , but the qdeadlinetimer.h error shown above still remains during the make procedure. Any hints?

Log in to reply