c++ - QPainter 设备返回引擎 == 0,类型 : 3 (in re-defined paint() method)

标签 c++ qt qpainter

我有一大块基于 Qt 的软件,它在我们使用的所有现代机器上运行得很好。我们尝试在旧机器上运行编译后的软件,当我们尝试构建更大的场景时软件崩溃并出现以下错误:

error log figure

程序中只有几个地方使用了 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/

相关文章:

c++ - 尝试处理嵌套对象/结构和动态数组时发生内存泄漏或内存错误。可能的 Xcode/malloc 问题

c++ - 如果数字为负,为什么在递归解决方案中查找给定序列中的最大子序列的基本情况返回 0?

qt - QPainter 宽度和高度

c++ - 使用 Chebyshev 距离探索矩阵

c++ - 如何实现一个奇怪的for循环

iphone - 移植 iphone 应用程序。如果您要从头开始重新启动您的应用程序,您会采取哪些不同的做法?

Qt 设计器自定义小部件 : using flags

c++ - 如何将复杂的指针数据作为属性放入 qt 插件 xml 文件中

c++ - 如何使用 QPainter 在 QMainWindow 中的一组小部件中的特定小部件上绘制?

c++ - Qt初学者: QPainter widget not rendering