Reputation: 1897
I am trying to print a graphic in Qt.
The signals and slots are connected as follows :
connectStat = connect(_ui->printButton, SIGNAL(clicked()), this, SLOT(doPrint()));
and the slot is as follows:
...
QGraphicsScene * m_scene;
...
void GraphDrawerWidget::doPrint() {
QPrinter printer;
if (QPrintDialog(&printer).exec() == QDialog::Accepted) {
printer.setOrientation(QPrinter::Landscape);
QPainter painter(&printer);
painter.setRenderHint(QPainter::Antialiasing);
m_scene->render(&painter);
}
}
The Print dialog does appear, and I can get the scene to print by clicking on the Print button. However, after I do this, the print dialog is showed again. It doesn't matter if I click Print, Cancel or the Window X button, it still shows after the click.
Am I possibly connecting the signals/slots wrong?
Upvotes: 0
Views: 160
Reputation: 1897
Found it! It seems I was doing the connect() in another method called run() (GraphDrawerWidget::run()) which is where I was feeding the data into the Graphic.
This run() got called once for each signal I was adding to the graphic, so the same slot was connected multiple times.
I am now connecting in the constructor and everything works fine.
Upvotes: 2