Results 1 to 12 of 12

Thread: getting weird QPainter error QPain::begin: Paint device returned engine == 0, type: 3

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2012
    Location
    Iran
    Posts
    34
    Thanks
    33
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default getting weird QPainter error QPain::begin: Paint device returned engine == 0, type: 3

    Hello Everyone,
    I tried adding two timers to my window one for showing the time that some method is being run, the other displaying some information regarding the same method.
    to be more precise, the first timer specifies the elapsed time in the realtime , in the form of "00:00:00:00" (as for day:hour:min:sec) that shows how long a method has been being running.
    the other timer, gets the progress information of the such method, meaning how many steps have been passed and how many remains, this kind of stuff .

    the first timer interval is set to emit every 1000ms , and the second timer is set to 10 ms.

    this is how the code looks like now :
    Qt Code:
    1. void frmCustomNetwork::Init()
    2. {
    3. InitFunctions();
    4.  
    5. //set timer
    6. timer = new QTimer(0);
    7. connect(timer,SIGNAL(timeout()),this,SLOT(on_TimerTick()));
    8. timer->setInterval(1000);
    9.  
    10.  
    11. timerfast = new QTimer(this);
    12. connect(timerfast,SIGNAL(timeout()),this,SLOT(on_TimerFastTick()));
    13. timerfast->setInterval(10);
    14.  
    15. //create a new network object
    16. net = new Network(Layers,Network::TrainMode::Sequential,0);
    17.  
    18. ui->customPlot->addGraph();
    19. // give the axes some labels:
    20. ui->customPlot->xAxis->setLabel("epochs");
    21. ui->customPlot->yAxis->setLabel("errors");
    22. // set axes ranges, so we see all data:
    23. ui->customPlot->xAxis->setRange(ui->txtXaxisLower->text().toFloat(), ui->txtXaxisUpper->text().toFloat());
    24. ui->customPlot->yAxis->setRange(ui->txtYaxisLower->text().toFloat(), ui->txtYaxisUpper->text().toFloat());
    25.  
    26. ui->sliderEpoch->setMaximum(ui->txtXaxisUpper->text().toInt());
    27. }
    28.  
    29. ...
    30.  
    31.  
    32. void frmCustomNetwork::on_btnTrain_clicked()
    33. {
    34. try
    35. {
    36. if( P.size() == 0 || T.size() == 0)
    37. {
    38. QMessageBox::warning(this,"No Sample for training is set","You need to specify some samples with their respective desired outputs first");
    39. return;
    40. }
    41.  
    42. elapsedSeconds=0;
    43. timer->start();
    44. timerfast->start();
    45. connect(&watcher,SIGNAL(finished()),this,SLOT(on_ThreadJobFinshed()));
    46. future = QtConcurrent::run(this,&frmCustomNetwork::Rec,ui->chkPlot->isChecked());
    47. watcher.setFuture(future);
    48.  
    49. }
    50. catch(QException ex)
    51. {
    52. QMessageBox::critical(this,"Exception occured in on_btnTrain_clicked()",ex.what());
    53. }
    54. catch(std::exception ex)
    55. {
    56. QMessageBox::critical(this,"Exception occured in on_btnTrain_clicked()",ex.what());
    57. }
    58. catch(...)
    59. {
    60. QMessageBox::critical(this,"Exception occured on_btnTrain_clicked()","Uknown Exception occured");
    61. }
    62. }
    To copy to clipboard, switch view to plain text mode 
    and these are the timers and watchers slot respectively.
    Qt Code:
    1. void frmCustomNetwork::on_TimerTick()
    2. {
    3. try
    4. {
    5. elapsedSeconds++;
    6.  
    7. day = elapsedSeconds / (24*3600);
    8. hour = (elapsedSeconds % (24*3600)) / 3600 ;
    9. min = ((elapsedSeconds % (24*3600)) % 3600) / 60;
    10. second = ((elapsedSeconds % (24*3600)) % 3600) % 60;
    11.  
    12. ui->lblElapsedTime->setText(QString::number(day)+" : "+QString::number(hour)+" : "+QString::number(min)+" : "+QString::number(second));
    13.  
    14. }
    15. catch(QException ex)
    16. {
    17. QMessageBox::critical(this,"Exception occured in on_btnTrain_clicked()",ex.what());
    18. }
    19. catch(...)
    20. {
    21. QMessageBox::critical(this,"Exception occured in on_btnTrain_clicked()","UnExpected Exception occured! ");
    22. }
    23. }
    24.  
    25. void frmCustomNetwork::on_TimerFastTick()
    26. {
    27. QString epoch = QString::number(net->GetCurrentEpochNumber());
    28. QString patternIndex = QString::number(net->GetCurrentPatternNumber());
    29.  
    30. ui->lblCurrentEpoch->setText(epoch);
    31. ui->lblCurrentPattern->setText(patternIndex);
    32.  
    33. }
    34.  
    35.  
    36. void frmCustomNetwork::on_ThreadJobFinshed()
    37. {
    38. timer->stop();
    39. timerfast->stop();
    40. elapsedSeconds = 0;
    41. }
    To copy to clipboard, switch view to plain text mode 

    Now when the application runs, everything is just fine, when the method in question ends, the application crashes , and inside QtCreator I can see these error messages:
    Qt Code:
    1. Starting G:\ProjectsCenter\ArtificialNeuralNetworksProject\QtProject\ANN\release\Ann.exe...
    2. QPainter::begin: Paint device returned engine == 0, type: 3
    3. QPainter::setCompositionMode: Painter not active
    4. QPainter::end: Painter not active, aborted
    5. The program has unexpectedly finished.
    6. G:\ProjectsCenter\ArtificialNeuralNetworksProject\QtProject\ANN\release\Ann.exe crashed
    To copy to clipboard, switch view to plain text mode 

    Update
    For some time it seems to be running just fine, but again it fails unexpectedly : here is another error message that poped up just after executing the method in question successfully for 3 times, (on the forth time this is what I get):
    Qt Code:
    1. QMetaObject::connectSlotsByName: No matching signal for on_btnLoadCorrectSamples_clicked()
    2. QMetaObject::connectSlotsByName: No matching signal for on_btnLoadWrongSamples_clicked()
    3. QPainter::begin: Paint device returned engine == 0, type: 3
    4. QPainter::setCompositionMode: Painter not active
    5. QPainter::end: Painter not active, aborted
    6. The program has unexpectedly finished.
    7. G:\ProjectsCenter\ArtificialNeuralNetworksProject\QtProject\ANN\release\Ann.exe crashed
    To copy to clipboard, switch view to plain text mode 
    Whats causing it ?

    I also tried putting
    Qt Code:
    1. QCoreApplication::processEvents();
    To copy to clipboard, switch view to plain text mode 
    in timer slots, but that doesnt prevent crashes.
    Last edited by Hossein; 12th October 2015 at 15:00.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: getting weird QPainter error QPain::begin: Paint device returned engine == 0, typ

    Quote Originally Posted by Hossein View Post
    the first timer specifies the elapsed time in the realtime , in the form of "00:00:00:00" (as for day:hour:min:sec) that shows how long a method has been being running.
    Just as an improvement: instead of incrementing a counter, start a QElapsedTimer when you start being interested in elapsed time and use its elapsed time counting.
    The QTimer is then only used for getting the current value and updating the UI.

    That way your display is always accurate, even if the timer event is delayed, etc.

    Quote Originally Posted by Hossein View Post
    Now when the application runs, everything is just fine, when the method in question ends, the application crashes , and inside QtCreator I can see these error messages:
    What is the method in question?
    Where does it crash according to the backtrace?

    Cheers,
    _

Similar Threads

  1. Replies: 1
    Last Post: 30th December 2013, 17:06
  2. Error Message "Paint device returned engine == 0, type:1"
    By yuzhouzhiwai in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2012, 09:33
  3. Replies: 0
    Last Post: 27th April 2012, 13:54
  4. Replies: 4
    Last Post: 25th February 2011, 09:01
  5. paint device returned engine == 0, type: 3
    By MarkoSan in forum Qt Programming
    Replies: 14
    Last Post: 12th December 2007, 10:42

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.