I'm now building with Qt5 code that compiled with no problems with Qt4, and getting an error message that is a bit obscure to me.

F:\Qt\5.13.0\msvc2017\include\QtCore\qmetatype.h:1 798: error: C2338: Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system
F:\Qt\5.13.0\msvc2017\include\QtCore\qmetatype.h:1 805: see reference to function template instantiation 'int qMetaTypeId<T>(void)' being compiled
with
[
T=QMouseEvent *
]
D:\testing\build-vspheroid-Qt3d\release\moc_myqgraphicsview.cpp:98: see reference to function template instantiation 'int qRegisterMetaType<QMouseEvent*>(void)' being compiled
F:\Qt\5.13.0\msvc2017\include\QtCore\qatomic.h:56: see reference to class template instantiation 'QBasicAtomicInteger<int>' being compiled
F:\Qt\5.13.0\msvc2017\include\QtCore\qatomic.h:154 : see reference to class template instantiation 'QAtomicInteger<int>' being compiled

I have extended QGraphicsView to allow image save on a mouse click like this:

myqgraphicsview.h:

Qt Code:
  1. #ifndef MYQGRAPHICSVIEW_H
  2. #define MYQGRAPHICSVIEW_H
  3.  
  4. #include <QWidget>
  5. #include <QGraphicsView>
  6. #include <QGraphicsScene>
  7. #include <QMouseEvent>
  8. #include <QFileDialog>
  9.  
  10. #include "log.h"
  11. LOG_USE();
  12.  
  13. class MyQGraphicsView : public QGraphicsView
  14. {
  15. Q_OBJECT
  16. public:
  17. explicit MyQGraphicsView(QWidget *parent = nullptr);
  18.  
  19. signals:
  20. void viewClicked();
  21. public slots:
  22. void mouseReleaseEvent(QMouseEvent * e);
  23. void saveImage();
  24. private:
  25. // member variable to store click position
  26. QPoint m_lastPoint;
  27. // member variable - flag of click beginning
  28. bool m_mouseClick;
  29. };
  30.  
  31. #endif // MYQGRAPHICSVIEW_H
To copy to clipboard, switch view to plain text mode 

myqgraphicsview.cpp:

Qt Code:
  1. #include "myqgraphicsview.h"
  2.  
  3. MyQGraphicsView::MyQGraphicsView(QWidget *parent) :
  4. QGraphicsView(parent)
  5. {
  6. }
  7.  
  8. void MyQGraphicsView::mouseReleaseEvent(QMouseEvent * e)
  9. {
  10. if (e->button() == Qt::RightButton) {
  11. saveImage();
  12. }
  13. }
  14.  
  15. void MyQGraphicsView::saveImage()
  16. {
  17. QGraphicsScene *ascene = this->scene();
  18. ascene->clearSelection(); // Selections would also render to the file
  19. ascene->setSceneRect(ascene->itemsBoundingRect()); // Re-shrink the scene to it's bounding contents
  20. QImage image(ascene->sceneRect().size().toSize(), QImage::Format_ARGB32); // Create the image with the exact size of the shrunk scene
  21. image.fill(Qt::transparent); // Start all pixels transparent
  22. QPainter painter(&image);
  23. ascene->render(&painter);
  24. QString fileName = QFileDialog::getSaveFileName(this, tr("Image File Name"), ".", tr("Image Files (*.png)"));
  25. if (fileName.compare("") != 0) {
  26. image.save(fileName);
  27. }
  28. }
To copy to clipboard, switch view to plain text mode 

I don't know where and how I should insert the Q_DECLARE_METATYPE line. I don't know what metatype it is referring to (or even what a metatype is).