I'm "kicking the tires" on QtSerialPort.
The Qt docs have this simple code fragment as an example of how to use SerialPortInfo:
// Example use SerialPortInfo
foreach (const SerialPortInfo &info, SerialPortInfo::availablePorts()) {
qDebug() << "Name : " << info.portName();
qDebug() << "Description : " << info.description();
qDebug() << "Manufacturer: " << info.manufacturer();
// Example use SerialPort
SerialPort serial;
serial.setPort(info);
if (serial.open(QIODevice::ReadWrite))
serial.close();
}
When I run the code, the loop runs once, and does the qDebug print. But, I get an exception when stepping out of the loop (at the curly brace).
I commented out nearly everything, and still get the exception:
int _tmain(int argc, _TCHAR* argv[])
{
QApplication app(argc, argv);
app.setOrganizationName("Flying Nerd");
app.setApplicationName("Stats Helpwer");
// MainWindow mainWin;
//mainWin.show();
//mainWin.raise();
// Example use SerialPortInfo
foreach (const SerialPortInfo &info, SerialPortInfo::availablePorts()) {
qDebug() << "Name : " << info.portName();
qDebug() << "Description : " << info.description();
qDebug() << "Manufacturer: " << info.manufacturer();
// Example use SerialPort
//SerialPort serial;
//serial.setPort(info);
//if (serial.open(QIODevice::ReadWrite))
// serial.close();
}
return app.exec();
}
I haven't been able to build the docs for QtSerialPort class either. If I knew what SerialPortInfo::availablePorts returns (a container of some sort for SerialPortInfo &, I'm thinking), I'd try avoiding use of the foreach and just iterate through the items in the container.
So, two questions:
1) Is there class documentation online somewhere for the QtSerialPort classes (if not, I'll struggle more with building the docs).
2) Anybody spot why I'm getting the exception?
Thanks,
Dave Thomas


Reply With Quote


Bookmarks