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. How am i can handle signal "fileselected" (QFileDialog)?[SOLVED]
QtWS25 Last Chance

How am i can handle signal "fileselected" (QFileDialog)?[SOLVED]

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 2.9k Views
  • 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.
  • L Offline
    L Offline
    LiUn
    wrote on last edited by
    #1

    Hello
    I have some problem with QFileDialog

    @QFileDialog dialog = new QFileDialog(this,"Save Map","",".map");
    dialog->setAcceptMode(QFileDialog::AcceptSave);
    dialog->show();
    connect(dialog, SIGNAL(fileSelected(QString)), this, SLOT(saveMap(QString)));@

    When I clicked "OK" , signal "fileSelected" is sent twice

    1 Reply Last reply
    0
    • X Offline
      X Offline
      Xander84
      wrote on last edited by
      #2

      Hi, are you sure you are not connecting the signal twice? maybe you are calling that code twice in a function and never disconnect the signal so you will always add to the same signal. Just an idea.
      You can try printing the "sender()" in the slot, see if its the same source or where it comes from.

      1 Reply Last reply
      0
      • L Offline
        L Offline
        LiUn
        wrote on last edited by
        #3

        I am sure that i'm not connecting the signal twice)
        I printing sender() and i get same address twice)

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chrisw01
          wrote on last edited by
          #4

          Hi LiUn, what version of QT, which OS, and what are you attempting to accomplish?

          1 Reply Last reply
          0
          • L Offline
            L Offline
            LiUn
            wrote on last edited by
            #5

            I am using Qt5.2, os - ubuntu
            I was trying disconnect from this signal when I getting it first time
            @void MainWindow::saveMap(QString name)
            {
            qDebug()<<"saveMap"<<name<<sender();
            disconnect(this,SLOT(saveMap(QString)));
            }
            @
            but this doesn't work

            1 Reply Last reply
            0
            • C Offline
              C Offline
              Chrisw01
              wrote on last edited by
              #6

              Hi LiUn, I mean that I assume that you are attempting to save a file using the QFileDialog?

              1 Reply Last reply
              0
              • L Offline
                L Offline
                LiUn
                wrote on last edited by
                #7

                yes, I'm attempting to save a file using the QFileDialog

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Chrisw01
                  wrote on last edited by
                  #8

                  Hi LiUn, I'm not sure why you would want use connections for anything in this instance, but I recommend trying the following.

                  @
                  QString fileName = QFileDialog::getSaveFileName(this, "Save Maps", QDir::currentPath(), "Map Files (.map);;All Files (.*)");
                  @

                  Then fileName either holds the fileName entered, or nothing if cancel was pressed.

                  1 Reply Last reply
                  0
                  • L Offline
                    L Offline
                    LiUn
                    wrote on last edited by
                    #9

                    oh, thank you ... I think I can use this code instead my

                    1 Reply Last reply
                    0
                    • C Offline
                      C Offline
                      Chrisw01
                      wrote on last edited by
                      #10

                      You are welcome, don't forget to mark as [SOLVED] if it fixes your problem.

                      Chris

                      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