I want to print a QGraphicsScene's contents. How do I do this? The following code is wrong

Qt Code:
  1. void MainWindow::print()
  2. {
  3. QPrinter printer;
  4. if (QPrintDialog(&printer).exec() == QDialog::Accepted) {
  5. QPainter painter(&printer);
  6. painter.setRenderHint(QPainter::Antialiasing);
  7. //QGraphicsScene scene = anotherQGraphicsView->scene();
  8. //What lines of code should I use to get another QGraphicsView's scene
  9. //No method like getScene() exists
  10. scene->render(&painter);
  11. }
  12. }
To copy to clipboard, switch view to plain text mode