Serial Port Interfacing In Qt

Well, for an embedded system guy, serial port is one of the most popular way to make your PC communicate with a target board, be it SBC or some serial based automation sort of work. Now, challenge is to use your own serial terminal software 😛 Well that’s the least what can be expected from a Qt Application developer.

Gui for the application

So this post is all about building an application which opens a serial port, and communicate with it. 

Now, the first need of the project is the library to work with. However, unlike Qt5.0, Qt4.0 does not come with serial port libraries, we have to include external library for the project.

One of such library is QextSerialPort which is supported by Qt4.0…

Follow these steps for downloading, building this library.

  • cd <any folder (preferrably to the QtSDK installation folder)>
  • git clone
  • cd qextserialport
  • qmake
  • make
  • make install

This will build this library. Now you can browse the folder for example programs.

Coming to the project. Since we need super-user permission to work with serial port. so better open Qt in su mode.

$sudo qtcreator

Now make the Gui as shown :

The objects are clear from the object and classes listing in the right side.

The use of all these comboBox elements are obvious from the names. There are two modes for the Polling is the method which utilises a timer to collect the data from the serial buffer after the timer runs out.

The status label in the bottom is just to show the status of the port, whether it is opened, closed etc..

Now comes the programming part:

1. Create a Qt Gui based dialog project named “”.

2. Create the UI as above. You can take the help from the example program in qextserialport library.

3. For static compilation of the projects, which is preferred here, these are the steps:

  • Add following line to the : (include /opt/QtSDK/qextserialport/src/qextserialport.pri)
  • Just include qextserialport.h in serialManager.h

4. To create a port:

QextSerialPort *port = new QextSerialPort(<portname>, <Querymode>);

to add the setting like databit, stopbit, etc syntax is as follows:



port->setDataBit(); etc..

Here is the final output screen.

Final output screen

However, make sure to short-circuit the RX -TX pins of DB-9 connector 😛

In case of my mini2440 connection to serialPort @115200 baudrate

the output screen looks like this:

The vivibootloader communication via SerialManager

here is the final codeuartAssistant.tar for downloading…

Hope you find this useful 🙂 thankyou..


About Shantanu Sharma

Currently working as Software R&D member in Samsung R&D India.

Posted on October 23, 2013, in Qt: The Face Of Embedded and tagged , , , . Bookmark the permalink. 2 Comments.

  1. lucas prado rocha

    Hi My name is lucas and iḿ new in qt enviroment and i already did what you put in your post and works fine , now id like to use the serial under a qml project , can you let me know how i can do it ?

  2. Hi…I am new to QT and i have asked to make a simple chat application in Qt using serial port in C++. Also timestamp the data and checksum should be there. Can you please mail me the code.its urgent please.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s