qt开发常见场景

1. QTableWidget在单元格中添加CheckBox并居中

QWidget *widget = new QWidget(ui->pointsTable);
QCheckBox *cBox = new QCheckBox;
QHBoxLayout *layout = new QHBoxLayout;
layout->setContentsMargins(2, 2, 2, 2);
layout->addWidget(cBox);
layout->setMargin(0);                      // 必须
layout->setAlignment(Qt::AlignHCenter);    // 必须
widget->setLayout(layout);
ui->pointsTable->setCellWidget(i, j, widget);

 

2. QMap迭代器删除元素崩溃

for(QMap::iterator it = _socketMap.begin(); it != _socketMap.end();) {
    if (it.value() == socket) {
          _socketMap.erase(it++);
    } else {
        ++it;
    }
}

 

你可能感兴趣的:(QT)