I have an ComboBox
in my QML file:
import QtQuick 2.4
import QtQuick.Controls 2.0
// ...
ComboBox {
id: serailPortNameBox
model: availableSerialPortsModel
textRole: "display"
}
and model availableSerialPortsModel
that contains serial port names currently available in system:
QStringListModel availableSerialPortsModel;
QList<QSerialPortInfo> portsList = QSerialPortInfo::availablePorts();
for (auto port : portsList) {
int row = availableSerialPortsModel.rowCount();
availableSerialPortsModel.insertRow(row);
QModelIndex index = availableSerialPortsModel.index(row);
availableSerialPortsModel.setData(index, port.portName(), Qt::DisplayRole);
}
// ...
engine.rootContext()->setContextProperty("availableSerialPortsModel", availableSerialPortsModel);
When I'm removing some serial port:
for (int row = availableSerialPortsModel.rowCount() - 1; row >= 0; --row) {
QModelIndex index = availableSerialPortsModel.index(row);
QString name = availableSerialPortsModel.data(index, Qt::DisplayRole).toString();
if (portsToRemove.contains(name)) {
availableSerialPortsModel.removeRow(row);
}
}
ComboBox
removes this port with some visual issue:
Is it just a bug og ComboBox
or am I doing something wrong? My Qt version is 5.7.0 on a Apple device with Sierra 10.12.2.
Here a simple project that reproduces the issue.
This is Qt 5.7.0 bug (bugreports.qt.io/browse/QTBUG-54573). Upgrading to Qt 5.7.1 id solved the problem.