- QT 6.6.0
- msvc2019_64
个人觉得QT的容器应该都有这个问题
使用QList程序崩溃
#include <QList>
#include <QtWidgets/QPushButton>
int main(int argc, char* argv[]) {
QList<QPushButton*> buttons;
buttons.push_back(new QPushButton());
buttons.push_back(new QPushButton());
for (QList<QPushButton*>::iterator it = buttons.begin(); it != buttons.end();) {
QPushButton* widget = *it;
widget->deleteLater();
buttons.erase(it++);/* Really smart! */
}
}
使用标准库std::list没有任何问题
#include <list>
#include <QtWidgets/QPushButton>
int main(int argc, char* argv[]) {
std::list<QPushButton*> buttons;
buttons.push_back(new QPushButton());
buttons.push_back(new QPushButton());
for (std::list<QPushButton*>::iterator it = buttons.begin(); it != buttons.end();) {
QPushButton* widget = *it;
widget->deleteLater();
buttons.erase(it++);/* Really smart! */
}
}