English | Deutsch | Русский | Polski | Nederlands | Português | Español | Українською | فارسی | عربي | 한국어 | Suomi | Català | Italiano | 日本語 | Français | Magyar | ಕನ್ನಡ | हिन्दी | ภาษาไทย | 简体中文 | Български

QtSerialPort

Note: this page is work in progress, needs review.

News

Fill up

02/26/2013 – The project moved from the playground to the trunk of Qt5!

Brief description

The QtSerialPort module is an add-on module for the Qt5 library, providing a single interface for both hardware and virtual serial ports.

Note: Also added support for Qt4.

Serial interfaces, due to their simplicity and reliability, are still popular in some industries like the development of embedded systems, robotics, etc.

Using the QtSerialPort module, developers can significantly reduce the time needed to implement Qt applications that require access to a serial interface.

History

QtSerialPort originated from the third-party library QSerialDevice [gitorious.org] (branch 2.0), which was recently moved to a repository on https://codereview.qt-project.org/

This was done to allow more open development, and to gather and coordinate a community that is interested in developing this module.

Functionality

Currently, the module API contains two classes: QSerialPort and QSerialPortInfo.

QSerialPort

QSerialPort is the base class of the module and provides a set of basic methods and properties to access resources on serial ports.

Supports the following operating systems:

Operating system Support state Note
Windows NT/2K/XP/Vista/7 YES Full support
Windows CEYESTested only on 5 and 6 platforms in the emulator
Gnu/Linux YESFull support
MacOSXYESFull support
Others UnixYESAll POSIX-compatible
Symbian1YESPartially, tested only in the emulator

1 For OS Symbian development of the module is suspended due to lack of developers, as well as the fact that Nokia has abandoned the platform and will not include support for it in Qt5.

QSerialPortInfo

QSerialPortInfo is a helper class. It provides information on the available serial ports on the system.

Supports the following operating systems:

Operating system Support state Note
Windows NT/2K/XP/Vista/7 YES Full support (using SetupAPI)
Windows CEYESTested only on 5 and 6 platforms in the emulator
Gnu/Linux YESFull support (using libudev or simple search in /dev)
MacOSXYESFull support
Others UnixYESAll POSIX-compatible (only simple search in /dev)
Symbian2YESPartially, tested only in the emulator

2 Symbian development of the module is suspended due to lack of developers, as well as the fact that Nokia has abandoned the platform and will not include support for it in Qt5.

View the source code

Recently launched a public mirror of the repository project at Gitorious [qt.gitorious.org]

Now everyone can freely and quickly view the latest changes through a WEB browser.

Getting the source code

For end-users

To get the current snapshot of the source code as an archive click on this [qt.gitorious.org] link.

Those who want to use Git can run the following command:

  1. git clone git://gitorious.org/qt/qtserialport.git

For developers

To get the source code and contribute to the development you need to register a Qt developer account and set it up for use with Gerrit and Git (see Setting up Gerrit [wiki.qt-project.org]).

You can then check out the repository using git, like this:

  1. git clone ssh://<username>@codereview.qt-project.org:29418/qt/qtserialport.git

…with your Gerrit user ID in place of <username>.

Building and Installing

Build and install from command line

Before building you need to:

  • install Perl3
  • ensure that the environment variables are set correctly:
    • correctly specified the path to the installed Qt4/Qt5
    • correctly specified the path to use the compiler
    • correctly specified the path to Perl3
  • create a build directory that is in the same level as the directory with the source code
    1. /
    2. |- /serialport-src
    3. |- /serialport-build

The following are the recommended steps for building the QtSerialPort library on Qt4/Qt5 from the command line.

  1. cd serialport-build
  2. qmake ../serialport-src/qtserialport.pro
  3. make [or 'nmake' for MSVC compiler, or 'mingw32-make' for MinGW compiler]
  4. make install [or 'nmake install' for MSVC compiler, or 'mingw32-make install' for MinGW compiler]

Note: on *nix systems super user privileges might be required:

  1. sudo make install

Build and install from the QtCreator

Using QtCreator is the simplest and fastest way to manually install the library.

Before building you need to:

  • install Perl3 and check that the path to Perl was correctly specified in a global env
  • check that the desired toolchains (kits) of QtCreator have been correctly configured

Recommended steps to build the QtSerialPort library for Qt4/Qt5 from QtCreator:

  • download and unpack the QtSerialPort sources
  • run QtCreator and open the “qtserialport.pro” project file
  • get to “Projects->(Your Kit)->Build->Build Steps”
  • add a new make “Build Step” and write to the “Make arguments” the install target
  • from the menus, select “Rebuild Project qtserialport”

As a result, the QtSerialPort library will be automatically compiled and installed into the desired Qt instance (according to the selected Kit).

Note: on *nix systems this method can be failed if Qt was installed from the repositories into system directories. Super user privileges may be required for “make install” target

3 Perl is required only in the case of Qt5, see here [qt-project.org]. When using Qt4 just skip this point.

Usage

To use the library, add serialport to the *.pro file of your project:

Qt4

  1. CONFIG += serialport

Qt5

  1. QT += serialport

Include the header files of QtSerialPort where appropriate:

  1. ...
  2. #include <QtSerialPort/QSerialPort>
  3. #include <QtSerialPort/QSerialPortInfo>
  4. ...

Simple example

Below is a simple example of main.cpp:

  1. #include <QtCore/QCoreApplication>
  2. #include <QtCore/QDebug>
  3.  
  4. #include <QtSerialPort/QSerialPort>
  5. #include <QtSerialPort/QSerialPortInfo>
  6.  
  7. QT_USE_NAMESPACE
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11.     QCoreApplication a(argc, argv);
  12.  
  13.     // Example use QSerialPortInfo
  14.     foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
  15.         qDebug() << "Name        : " << info.portName();
  16.         qDebug() << "Description : " << info.description();
  17.         qDebug() << "Manufacturer: " << info.manufacturer();
  18.  
  19.         // Example use QSerialPort
  20.         QSerialPort serial;
  21.         serial.setPort(info);
  22.         if (serial.open(QIODevice::ReadWrite))
  23.             serial.close();
  24.     }
  25.    
  26.     return a.exec();
  27. }

Note: CONFIG += serial port / QT += serialport must be the first or second line in your .pro file.

Documentation generation

There is no need to build the documentation, because the documentation is available here [doc-snapshot.qt-project.org].

For those wishing to contribute to the development

All development is done through Gerrit [wiki.qt-project.org]. Therefore, those wishing to be involved in the development process must have a Qt developer account.

More information about the registration process and development can be found here [wiki.qt-project.org]

Possible problems

Fill up

Bug Tracking

Use bugreports.qt-project.org [bugreports.qt-project.org], Project “Qt”, Component “Serial Port”.

Categories: