我有一大块基于 Qt 的软件,它在我们使用的所有现代机器上运行得很好。我们尝试在旧机器上运行编译后的软件,当我们尝试构建更大的场景时软件崩溃并出现以下错误:
程序中只有几个地方使用了 QPainter
,它在 的继承类的重新定义方法
,例如:paint()
中>QStyledItemDelegate
virtual void paint(QPainter *painter,
const QStyleOptionViewItem &option,
const QModelIndex &index) const
{
QStyledItemDelegate::paint(painter, option, index);
// ...
QApplication::style()->drawControl(QStyle::CE_PushButtonLabel, &buttonDelete, painter);
}
问题是 QPainter
出现此类问题的原因可能是什么?这可能与可用内存有关,因为它在所有现代机器上似乎都很好吗?有什么建议可以在这里完成吗?
最佳答案
older machine
+
the software crashes when we try to build bigger scenes
= 很可能内存不足。您可以安装内存不足处理程序以在发生这种情况时得到通知:
#include <cstdio>
#include <new>
void my_new_handler()
{
printf("Memory allocation failed, terminating\n");
std::set_new_handler(nullptr);
}
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
std::set_new_handler(my_new_handler);
...
return app.exec();
}
关于c++ - QPainter 设备返回引擎 == 0,类型 : 3 (in re-defined paint() method),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44332361/