[SOLVED] QFileDialog::getSaveFileName - dialog is shown more then one time by call
-
I have next code:
@
QImage image(centralWidget_->rect().size(), QImage::Format_RGB32);
QPainter painter (&image);
painter.setRenderHint(QPainter::Antialiasing, true);
// Model is QGraphicsScene subclass
model_->clearSelection();
model_->render(&painter);QString fileName = QFileDialog::getSaveFileName(NULL, tr("export as image:"), QDir::homePath(), QString(tr("Images: *.png *.jpg")) ); if (!fileName.isEmpty()) { image.save(fileName); }
.......
@
When file's name has been chosen and i have pushed "save" button, this dialog appears again.
I use Qt 5.2 on debian linux. -
Hi and welcome to devnet,
Where is that code called from ?
-
[quote author="SGaist" date="1400881802"]Hi and welcome to devnet,
Where is that code called from ?[/quote]
This is SLOT of QMainWindow subclass.
-
Is your slot connected twice ?
-
[quote author="SGaist" date="1400882242"]Is your slot connected twice ?[/quote]
Do you mean that my slot is called twice at time in this case?
-
Yes exactly
-
I have class which contain next:
@
private slots:
void loadFile();
........
private:
GraphModel *model_;
QGraphicsView *centralWidget_;
........
@loadFile() has next code:
@
if (gl(fileName, model)) {
model->setParent(this);
delete model_;
model_ = model;
centralWidget_->setScene(model_);
connectModel();
......
@
Will after it model connected two time's? So how to correctly exchange my model? -
The problem is that these pieces of code don't tell much. Somewhere you are connecting something at least twice. So where does that connect happen and why several times ?
-
[quote author="SGaist" date="1400884197"]The problem is that these pieces of code don't tell much. Somewhere you are connecting something at least twice. So where does that connect happen and why several times ?[/quote]
You are right. Error was in connectModel() call which contain connect of MainWindow to it's own slot.
You have helped me, thank you very much!!!
-
You're welcome !
Since you have it working now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)