March 28, 2011

harry harry
Lab Rat
108 posts

QPainter::begin: Paint device returned engine == 0, type: 2

 

This is a long shot given the nature of my problem, but can anyone here help me debug this message I’m seeing in my debug output?
QPainter::begin: Paint device returned engine == 0, type: 2

It occurs when I add about 10 columns with checkboxes to a QTreeView and QTreeWidget, and I hover over the columns or resize them.

I tried first with a QTreeWidget and creating everything manually (like calling setItemWidget(..) with a QCheckBox as an argument.
I then tried it with a QStandardItemModel by adding QStandardItems with setCheckable set to true.

I get the exact same behaviour: a few messages like that every now and then.
The actual functionality of the form and control don’t seem to be affected; Should I just ignore it?
I am running under Windows 7/64 bit with QtCreator 2.1 (my app is not 64 bit).

Thank you,
Harry Sfougaris

 Signature 

If you can’t say what you mean, you’ll never be able to mean what you say.

13 replies

March 28, 2011

ZapB ZapB
Ant Farmer
1426 posts

Have you tried debugging into Qt to see what causes this message (you’ll need a debug build of Qt)? Can you provide a small compilable example that reproduces this please?

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

March 28, 2011

shiroki shiroki
Lab Rat
6 posts

I agree with ZapB. You have to provide a compilable example or a backtrace for this issue. without seeing the code, it’s impossible to tell what the problem is.

March 29, 2011

harry harry
Lab Rat
108 posts

Ok, here it is.

Since I can’t attach the project:
It’s a simple project, the one creator generates.
I added in designer a treeview to the MainWindow and laid it out vertically.

mainwindow.h

  1. #ifndef MAINWINDOW_H
  2. #define MAINWINDOW_H
  3.  
  4. #include <QMainWindow>
  5. #include <QStandardItemModel>
  6.  
  7. namespace Ui {
  8.     class MainWindow;
  9. }
  10.  
  11. class MainWindow : public QMainWindow
  12. {
  13.     Q_OBJECT
  14.  
  15. public:
  16.     explicit MainWindow(QWidget *parent = 0);
  17.     ~MainWindow();
  18.  
  19. private:
  20.     Ui::MainWindow *ui;
  21.     void prepareDataSrc();
  22.     QStandardItemModel *dataSrc;
  23. };
  24.  
  25. #endif // MAINWINDOW_H

mainwindow.cpp:

  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3. #include <QStandardItem>
  4.  
  5. MainWindow::MainWindow(QWidget *parent) :
  6.     QMainWindow(parent),
  7.     ui(new Ui::MainWindow)
  8. {
  9.     ui->setupUi(this);
  10.     dataSrc = new QStandardItemModel();
  11.     prepareDataSrc();
  12.     ui->tVw->setModel(dataSrc);
  13.     ui->tVw->expandAll();
  14.     ui->tVw->setColumnWidth(0, 250);
  15. }
  16.  
  17. void MainWindow::prepareDataSrc(){
  18.     QStringList hdr;
  19.     hdr << "Descr" << "Col0" << "Col1" << "Col2" << "Col3" << "Col4" << "Col5" << "Col6" << "Col7" << "Col8" << "Col9";
  20.  
  21.     dataSrc->setHorizontalHeaderLabels(hdr);
  22.  
  23.     for (int i = 0; i < 100; i++) {
  24.         QList<QStandardItem*> iRow;
  25.         QStandardItem *iDescr = new QStandardItem();
  26.         iDescr->setText( QString("Item #%1").arg(i));
  27.         iDescr->setEditable(false);
  28.         iDescr->setData(i, Qt::UserRole);
  29.  
  30.         iRow << iDescr;
  31.         for (int i2 = 0; i2 < 10; i2++) {
  32.             QStandardItem *_i = new QStandardItem();
  33.             _i->setCheckable(true);
  34.             _i->setEditable(false);
  35.             _i->setTristate(false);
  36.             _i->setData(i2, Qt::UserRole);
  37.              _i->setCheckState(Qt::Checked);
  38.              iRow << _i;
  39.         }
  40.         if (iDescr->hasChildren()) {
  41.             QFont f = iDescr->font();
  42.             f.setBold(true);
  43.             iDescr->setFont(f);
  44.         }
  45.         dataSrc->invisibleRootItem()->appendRow(iRow);
  46.     }
  47. }
  48.  
  49. MainWindow::~MainWindow()
  50. {
  51.     delete ui;
  52. }

main.cpp:

  1. #include <QtGui/QApplication>
  2. #include "mainwindow.h"
  3. #include <QTextCodec>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7.     QString c = "UTF-8";
  8.     QTextCodec::setCodecForTr(QTextCodec::codecForName(c.toLatin1()));
  9.     QTextCodec::setCodecForCStrings(QTextCodec::codecForName(c.toLatin1()));
  10.     QTextCodec::setCodecForLocale(QTextCodec::codecForName(c.toLatin1()));
  11.  
  12.     QApplication a(argc, argv);
  13.     MainWindow w;
  14.     w.show();
  15.  
  16.     return a.exec();
  17. }

This reproduces it for me.
Thank you,
Harry

 Signature 

If you can’t say what you mean, you’ll never be able to mean what you say.

March 29, 2011

ZapB ZapB
Ant Farmer
1426 posts

I have tried it here (Gentoo Linux, Qt 4.7.2, raster paint engine) and I get no warnings at all from your example.

What version of Qt are you using? Did you build it yourself or is it a pre-compiled binary distribution of Qt? What paint engine are you using?

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

March 29, 2011

harry harry
Lab Rat
108 posts

I am running under Windows 7/64 bit with QtCreator 2.1.
I am using the pre-compiled binary distribution from Qt.

Paint engine? I don’t know what you mean… I haven’t done anything to explicitly use a particular engine.

 Signature 

If you can’t say what you mean, you’ll never be able to mean what you say.

March 29, 2011

ZapB ZapB
Ant Farmer
1426 posts

OK so you are likely using the raster paint engine then as that is the default on Windows.

Which version of Qt though? 4.7.0, 4.7.1, 4.7.2? Something older?

 Signature 

Nokia Certified Qt Specialist
Interested in hearing about Qt related work

March 29, 2011

harry harry
Lab Rat
108 posts

I’m sorry I missed to specify it… 4.7.2

 Signature 

If you can’t say what you mean, you’ll never be able to mean what you say.

March 29, 2011

Gerolf Gerolf
Robot Herder
3253 posts

Hi,

on windows using MSVS 2008 and pre build binaries, on Win7 32 bit, I can’t reproduce this behavior.
But if you look at the Qt code it is printed out, when

  1. bool QPainter::begin(QPaintDevice *pd)
  2. {
  3.     ....
  4.  
  5.     d->engine = pd->paintEngine();
  6.  
  7.     if (!d->engine) {
  8.         qWarning("QPainter::begin: Paint device returned engine == 0, type: %d", pd->devType());
  9.         return false;
  10.     }
  11.  
  12.     ....

It could perhaps be a 64 bit issue.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

March 29, 2011

harry harry
Lab Rat
108 posts

But my app isn’t a 64 bit app…
Thankfully whatever it misses to paint is not visible, but it’s still strange…

 Signature 

If you can’t say what you mean, you’ll never be able to mean what you say.

March 29, 2011

Gerolf Gerolf
Robot Herder
3253 posts

But you are using 64 but win 7.
Ups sorry, my system is win XP, not win 7

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

March 29, 2011

harry harry
Lab Rat
108 posts

So I guess this needs to be verified by someone running Win7/64 bit, to see if it can be reproduced…

 Signature 

If you can’t say what you mean, you’ll never be able to mean what you say.

April 1, 2011

harry harry
Lab Rat
108 posts

can anyone running Win7/64 bit, please run the above code to see if it can be reproduce?

 Signature 

If you can’t say what you mean, you’ll never be able to mean what you say.

December 28, 2012

J van Pinxten J van Pinxten
Lab Rat
1 posts

Just tried this with W7/64 on Qt 4.8.3 MinGW distribution, no messages or warnings running this code. Also tried 4.7.4 MinGW distribution, no warnings there. It shows the items properly, the checkboxes and list also behave properly.

 
  ‹‹ Unable to load qodbc driver not loaded      Using lastInsertId() functionality with QSqlTableModel ››

You must log in to post a reply. Not a member yet? Register here!