Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QFileDialog::getSaveFileName - dialog is shown more then one time by call

[SOLVED] QFileDialog::getSaveFileName - dialog is shown more then one time by call

Scheduled Pinned Locked Moved General and Desktop
10 Posts 2 Posters 2.9k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    andy_march
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      Where is that code called from ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andy_march
        wrote on last edited by
        #3

        [quote author="SGaist" date="1400881802"]Hi and welcome to devnet,

        Where is that code called from ?[/quote]

        This is SLOT of QMainWindow subclass.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Is your slot connected twice ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andy_march
            wrote on last edited by
            #5

            [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?

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Yes exactly

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andy_march
                wrote on last edited by
                #7

                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?

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  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 ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andy_march
                    wrote on last edited by
                    #9

                    [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!!!

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      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 :)

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved