diff options
author | Laszlo Papp <lpapp@kde.org> | 2013-03-24 08:43:25 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-03-26 08:31:13 +0100 |
commit | 865e169fa6c4a5eeb182f87ac6dd3b72d5012ebf (patch) | |
tree | f54d8a837901f17c041e017670b0e3c2c2803c1e /examples | |
parent | eacecbe76e967e59a4cd0f873471693df7bb9e63 (diff) | |
download | qtserialport-865e169fa6c4a5eeb182f87ac6dd3b72d5012ebf.tar.gz |
Add accessor methods for checking the availability of the PID/VID
As mentioned in the previous change, this is necessary for those end users who
would like to explicitly know if the device on the serial port has a valid
vendor or/and product identifier.
This is now providing a nice and convenient API for having a dedicated boolean
method for making this query possible. It is a lot more readable and convenient
to use than other alternatives including the extended scope for the integer
query method and so forth. It is more explicit and clear about the intention
that one checks if the device has a valid identifier. It would be more vague
with error codes and so forth. One somewhat reasonable alternative could be
this, albeit this is also more inconvenient:
a) bool vendorIdentifier(quint16 &vendorIdentifier) const;
b) bool productIdentifier(quint16 &vendorIdentifier) const;
... as this would require an additional variable from the user, and this
could not be used with ternary operators so easily, et cetera.
There are even worse ideas like how the exceptional conversion happens in
QString and so forth, but that also requires an explicit variable or zero if one
is sure the conversion should succeed. One can pass zero in there, but that is
still inconvenient and more than passing nothing, and zero can become unclear
what it supposed to present half or one year later.
The change has been tested on Linux with Qt4 and Qt5, and cenumerator works as
expected. The documentation has been added accodingly.
Task-number: QTPLAYGROUND-21
Change-Id: I905708ce0e67307bf89d69e645462486ad869b0c
Reviewed-by: Sergey Belyashov <Sergey.Belyashov@gmail.com>
Reviewed-by: Denis Shienkov <denis.shienkov@gmail.com>
Diffstat (limited to 'examples')
-rw-r--r-- | examples/cenumerator/main.cpp | 4 | ||||
-rw-r--r-- | examples/enumerator/main.cpp | 4 | ||||
-rw-r--r-- | examples/terminal/settingsdialog.cpp | 4 |
3 files changed, 6 insertions, 6 deletions
diff --git a/examples/cenumerator/main.cpp b/examples/cenumerator/main.cpp index 3ae7d65..f55b92d 100644 --- a/examples/cenumerator/main.cpp +++ b/examples/cenumerator/main.cpp @@ -59,8 +59,8 @@ int main(int argc, char *argv[]) << QObject::tr("Location: ") << serialPortInfo.systemLocation() << endl << QObject::tr("Description: ") << serialPortInfo.description() << endl << QObject::tr("Manufacturer: ") << serialPortInfo.manufacturer() << endl - << QObject::tr("Vendor Identifier: ") << QByteArray::number(serialPortInfo.vendorIdentifier(), 16) << endl - << QObject::tr("Product Identifier: ") << QByteArray::number(serialPortInfo.productIdentifier(), 16) << endl + << QObject::tr("Vendor Identifier: ") << (serialPortInfo.hasVendorIdentifier() ? QByteArray::number(serialPortInfo.vendorIdentifier(), 16) : QByteArray()) << endl + << QObject::tr("Product Identifier: ") << (serialPortInfo.hasProductIdentifier() ? QByteArray::number(serialPortInfo.productIdentifier(), 16) : QByteArray()) << endl << QObject::tr("Busy: ") << (serialPortInfo.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) << endl; } diff --git a/examples/enumerator/main.cpp b/examples/enumerator/main.cpp index a95ee76..9e34d38 100644 --- a/examples/enumerator/main.cpp +++ b/examples/enumerator/main.cpp @@ -61,8 +61,8 @@ int main(int argc, char *argv[]) + QObject::tr("Location: ") + info.systemLocation() + "\n" + QObject::tr("Description: ") + info.description() + "\n" + QObject::tr("Manufacturer: ") + info.manufacturer() + "\n" - + QObject::tr("Vendor Identifier: ") + QString::number(info.vendorIdentifier(), 16) + "\n" - + QObject::tr("Product Identifier: ") + QString::number(info.productIdentifier(), 16) + "\n" + + QObject::tr("Vendor Identifier: ") + (info.hasVendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString()) + "\n" + + QObject::tr("Product Identifier: ") + (info.hasProductIdentifier() ?QString::number(info.productIdentifier(), 16) : QString()) + "\n" + QObject::tr("Busy: ") + (info.isBusy() ? QObject::tr("Yes") : QObject::tr("No")) + "\n"; QLabel *label = new QLabel(s); diff --git a/examples/terminal/settingsdialog.cpp b/examples/terminal/settingsdialog.cpp index 4533da9..65f6b87 100644 --- a/examples/terminal/settingsdialog.cpp +++ b/examples/terminal/settingsdialog.cpp @@ -157,8 +157,8 @@ void SettingsDialog::fillPortsInfo() << info.description() << info.manufacturer() << info.systemLocation() - << QString::number(info.vendorIdentifier(), 16) - << QString::number(info.productIdentifier(), 16); + << (info.vendorIdentifier() ? QString::number(info.vendorIdentifier(), 16) : QString()) + << (info.productIdentifier() ? QString::number(info.productIdentifier(), 16) : QString()); ui->serialPortInfoListBox->addItem(list.first(), list); } |