From 5a9fc73a2569f2d52119f08a20f35ec343a75753 Mon Sep 17 00:00:00 2001 From: Denis Shienkov Date: Sat, 31 Mar 2012 23:28:48 +0400 Subject: Added an enumerator example. Change-Id: If88a0a300bcd011489be462536fadadf16da6171 Reviewed-by: Sergey Belyashov Reviewed-by: Denis Shienkov --- examples/enumerator/enumerator.pro | 8 ++++++++ examples/enumerator/main.cpp | 39 ++++++++++++++++++++++++++++++++++++++ examples/examples.pro | 2 +- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 examples/enumerator/enumerator.pro create mode 100644 examples/enumerator/main.cpp (limited to 'examples') diff --git a/examples/enumerator/enumerator.pro b/examples/enumerator/enumerator.pro new file mode 100644 index 00000000..a6e1d8d2 --- /dev/null +++ b/examples/enumerator/enumerator.pro @@ -0,0 +1,8 @@ +QT += widgets serialport + +TARGET = enumerator +TEMPLATE = app + + +SOURCES += \ + main.cpp \ No newline at end of file diff --git a/examples/enumerator/main.cpp b/examples/enumerator/main.cpp new file mode 100644 index 00000000..2d737fad --- /dev/null +++ b/examples/enumerator/main.cpp @@ -0,0 +1,39 @@ +#include +#include +#include +#include +#include + +QT_USE_NAMESPACE_SERIALPORT + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + + QWidget w; + w.setWindowTitle(QObject::tr("Info about all available serial ports.")); + QVBoxLayout *layout = new QVBoxLayout; + + foreach (const SerialPortInfo &info, SerialPortInfo::availablePorts()) { + QString s(QObject::tr("Port: %1\n" + "Location: %2\n" + "Description: %3\n" + "Manufacturer: %4\n" + "Vid: %5\n" + "Pid: %6\n" + "Busy: %7\n")); + + s = s.arg(info.portName()).arg(info.systemLocation()) + .arg(info.description()).arg(info.manufacturer()) + .arg(info.vid()).arg(info.pid()) + .arg(info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")); + + QLabel *label = new QLabel(s); + layout->addWidget(label); + } + + w.setLayout(layout); + w.show(); + + return a.exec(); +} diff --git a/examples/examples.pro b/examples/examples.pro index 9a207e52..33716ef4 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -1,3 +1,3 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS = terminal +SUBDIRS = terminal enumerator -- cgit v1.2.3