[SOLVED] Lighter setup for serial port parameters (qSerialDevice)
Hey there
If I want to save the last serial port parameters to initialize this port at the next program start, I used always big switch statements like this one:
- switch(i)
- {
- case 0:
- port->setParity(SerialPort::EvenParity);
- break;
- case 1:
- port->setParity(SerialPort::OddParity);
- break;
- case 2:
- port->setParity(SerialPort::NoParity);
- break;
- case 3:
- port->setParity(SerialPort::MarkParity);
- break;
- case 4:
- port->setParity(SerialPort::SpaceParity);
- break;
- }
Is it possible to save these different serial port parameters into a QList or something similar, so I would be able to reduce all of this into one line? Something like this:
- QList<SerialPort> databits << SerialPort::Data5 << SerialPort::Data6 << SerialPort::Data7 << SerialPort::Data8;
And then:
- port->setDataBits(databits[i]);
Unfortunately it does not work with a QList, or I haven’t found the right method to do this.
4 replies
Thx for the advice. As you said my fault was the type of the QList. I just needed to set the type to:
with the DataBits enum for example.
It is also possible to use the integer value. But in my application I use QComboBox to adjust the serialPort. Finally I save the index value of the QComboBox when the settings are applied. If I want to use these integers to set the serial port parameteres it gets a bit confusing because the enums have different values. For example:
- enum Parity {
- NoParity = 0,
- EvenParity = 2,
- OddParity = 3,
- SpaceParity = 4,
- MarkParity = 5,
- UnknownParity = -1
- };
Therefore it’s anyway useful to fill a QList in the order like you want it, isn’t it?
You must log in to post a reply. Not a member yet? Register here!


