Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.
Qt Serial Port: Difference between revisions
Line 116: | Line 116: | ||
|Partially for Qt4, tested only in the emulator | |Partially for Qt4, tested only in the emulator | ||
|} | |} | ||
== Getting the source code == | == Getting the source code == |
Revision as of 13:05, 13 March 2015
This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Auto-imported from ExpressionEngine. Please improve this article if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean. |
English | Deutsch | Русский | Polski | Nederlands | Português | Español | Українською | فارسی | عربي | 한국어 | Suomi | Català | Italiano | 日本語 | Français | Magyar | ಕನ್ನಡ | हिन्दी | ภาษาไทย | 简体中文 | Български
Note: this page is work in progress, needs review.
News
- 2013-07-03 - As of Qt 5.1, Qt Serial Port is now officially part of Qt. You no longer need to build Qt Serial Port manually; simply install Qt 5.1 or later.
- 2013-02-26 - 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.
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 XP/Vista/7/8 | 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 |
Symbian[1] | YES | Partially for Qt4, tested only in the emulator |
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 XP/Vista/7/8 | 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) |
Symbian[2] | YES | Partially for Qt4, tested only in the emulator |
Getting the source code
You should clone from the official mirror and track changes from there in order to keep the load on Gerrit down.
$ git clone git://code.qt.io/qt/qtserialport.git $ cd qtserialport
This repository contains both versions for Qt4 and Qt5.
To take the version for Qt4 it is necessary to do[3]:
$ git checkout qt4-dev
To take the version for Qt5 it is necessary to do:
$ git checkout qt5.x.y
where x and y is a versions of available branches, which can be displayed after:
$ git branch -a
Building and Installing
Build and install from command line
Before building you need to:
- install Perl³
- 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 Perl³
- create a build directory that is in the same level as the directory with the source code
/
|- /serialport-src
|- /serialport-build
The following are the recommended steps for building the QtSerialPort library on Qt4/Qt5 from the command line.
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:' on nix systems super user privileges might be required:_
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 Perl³ 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_
³Perl is required only in the case of Qt5, see here. When using Qt4 just skip this point.
Usage
To use the library, add serialport to the *.pro file of your project:
Qt4
CONFIG += serialport
Qt5
QT += serialport
Include the header files of QtSerialPort where appropriate:
…
#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[])
{
QCoreApplication a(argc, 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);
if (serial.open(QIODevice::ReadWrite))
serial.close();
}
return a.exec();
}
Documentation generation
There is no need to build the documentation, because the documentation is available here.
For those wishing to contribute to the development
All development is done through Gerrit. 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
Possible problems
Fill up
Bug Tracking
Use bugreports.qt.io, Project "Qt", Component "Serial Port".
- ↑ 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.
- ↑ 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.
- ↑ Now QtSerialPort has a separate branch for Qt4 (similar to Qt4 itself), which will be only in one instance.