English | Deutsch | Русский | Polski | Nederlands | Português | Español | Українською | فارسی | عربي | 한국어 | Suomi | Català | Italiano | 日本語 | Français | Magyar | ಕನ್ನಡ | हिन्दी | ภาษาไทย | 简体中文 | Български
Table of Content
QtSerialPort
Note: this page is work in progress, needs review.
News
Fill up
02/26/2013 – The project moved from the playground to trunk Qt5!
Brief description
The QtSerialPort module is an add-on for the Qt5 library, providing a single interface for both hardware and virtual serial ports.
Note: Also added support and for library 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: SerialPort and SerialPortInfo.
SerialPort
SerialPort 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 CE | YES | Tested only on 5 and 6 platforms in the emulator |
| Gnu/Linux | YES | Full support |
| MacOSX | YES | Full support |
| Others Unix | YES | All POSIX-compatible |
| Symbian1 | YES | Partially, 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 the Qt5.
SerialPortInfo
SerialPortInfo 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 CE | YES | Tested only on 5 and 6 platforms in the emulator |
| Gnu/Linux | YES | Full support (using libudev or simple search in /dev) |
| MacOSX | YES | Full support |
| Others Unix | YES | All POSIX-compatible (only simple search in /dev) |
| Symbian2 | YES | Partially, tested only in the emulator |
2 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 the Qt5.
View the source code
Recently launched a public mirror of repository project at Gitorious [qt.gitorious.org]
Now everyone can freely and quickly through a WEB browser to view the latest changes in the source code of the project.
Getting the source code
For users
To get the current snapshot source code repository as an archive of WEB browser is enough to click on this [qt.gitorious.org] link, the download will start automatically.
For those who want to use Git can run the following command:
- 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:
- git clone ssh://<username>@codereview.qt-project.org:29418/qt/qtserialport.git
…with your Gerrit user ID in place of <username>.
Building and Installing
Note: At build process a better use of the “shadow build” when the results of building put out to a separate build directory. This allows us to keep the source directory intact, without clogging of products of build.
Before building the 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 used the compiler
- correctly specified the path to the Perl3
- create a build directory that is on the same level as the directory with the source code
- /
- |- /serialport-src
- |- /serialport-build
3 Perl is required only in the case of Qt5, see here [qt-project.org]. When using Qt4 just skip this point.
The following are recommended procedures for the build of QtSerialPort library on Qt4/Qt5.
- cd serialport-build
- qmake ../serialport-src/qtserialport.pro
- make [or 'nmake' for MSVC compiler, or 'mingw32-make' for MinGW compiler]
- make install [or 'nmake install' for MSVC compiler, or 'mingw32-make install' for MinGW compiler]
Note: in *nix systems may be required for the installation a super user privileges:
- sudo make install
Usage
When using the library, must connect it to the *.pro file of custom project, this step for Qt4 and Qt5 slightly different:
Qt4
- CONFIG += serialport
Qt5
- QT += serialport
Include the header files of QtSerialPort to the user project is same for Qt4 and Qt5:
- ...
- #include <QtSerialPort/QSerialPort>
- #include <QtSerialPort/QSerialPortInfo>
- ...
Simple example
Below is a simple example of main.cpp:
- #include <QtCore/QCoreApplication>
- #include <QtCore/QDebug>
- #include <QtSerialPort/QSerialPort>
- #include <QtSerialPort/QSerialPortInfo>
- QT_USE_NAMESPACE
- int main(int argc, char *argv[])
- {
- // Example use QSerialPortInfo
- foreach (const QSerialPortInfo &info, QSerialPortInfo::availablePorts()) {
- qDebug() << "Name : " << info.portName();
- qDebug() << "Description : " << info.description();
- qDebug() << "Manufacturer: " << info.manufacturer();
- // Example use QSerialPort
- QSerialPort serial;
- serial.setPort(info);
- serial.close();
- }
- return a.exec();
- }
Note: CONFIG += serialport must be the first or second line in your .pro file.
Documentation generation
There is no need for documentation building, because snapshot of 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 Playground Projects”, Component “qtserialport”.

