Results 1 to 3 of 3

Thread: QFileDialog called twice?

  1. #1
    Join Date
    Sep 2010
    Location
    Denmark
    Posts
    28
    Thanks
    10
    Thanked 3 Times in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default QFileDialog called twice?

    Hi,
    I have a problem that is driving me crazy.
    I am working on an animation software. I made a suggestion for a Xsheet feature, that would show you the present drawings in your project. In the QDialog there was a Papagayo button, and if you pressed the button, you could choose a papagayo file, and have the contents loaded to the QStringList mPapaLines, from where it is written to the Xsheet (a QTableWidget). It worked flawlessly.
    There are two functions loadPapa() and writePapa(). loadPapa() is called when you open the file, and read its content into a QStringList. writePapa() is called after loadPapa(), and everytime there are changes in the Xsheet.
    Now I have (upon request) made the xsheet dockable, It is the same code and it still works, but the filedialog appears twice?! I have to pick the file twice? After I have picked it the first time, it loads the data into the xsheet, so it calls AND executes the writePapa function, before it reopens the fileDialog. Why? The function loadPapa is 100% the same code as before I made it dockable.
    Qt Code:
    1. void Xsheet::loadPapa()
    2. {
    3. mPapaLines->clear();
    4. QString fileName = QFileDialog::getOpenFileName(this,
    5. tr("Open *.pgo file"), "", tr("Pgo Files (*.pgo)"));
    6. QFile file(fileName);
    7. if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
    8. return;
    9. QTextStream in(&file);
    10. while (!in.atEnd()) {
    11. QString tmp = in.readLine();
    12. tmp.remove("\t");
    13. mPapaLines->append(tmp);
    14. }
    15. file.close();
    16. writePapa();
    17. }
    To copy to clipboard, switch view to plain text mode 
    I have debugged it and I have set breakpoints. The result is the same.
    • It loads the papagayo file and closes the file.
    • It calls the writePapa(), and writes in the xsheet
    • it goes back to the ‘}’ after the writePapa() call
    • It jumps up to QTextStream in(&file);
    • It jumps up to QFile file(fileName)
    • it jumps back to the dialog, and opens the dialog…
    • If I press Cancel the second time, it returns on the if (!file.open…, and the mPapaLines is empty, which means that the column will be erased at the next updateUi.

    If I do a grep for loadPapa, it shows three results:
    app/src/xsheet.cpp:48: connect(ui->btnPapa, SIGNAL(clicked(bool)), this, SLOT(loadPapa()));
    app/src/xsheet.cpp:130:void Xsheet::loadPapa()
    app/src/xsheet.h:37: void loadPapa();

    There are no connections made in the xsheet.ui, and I am out of ideas.
    Can anyone explain what is happening?

  2. #2
    Join Date
    Jan 2006
    Location
    Bremen, Germany
    Posts
    554
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QFileDialog called twice?

    Maybe xsheet.cpp:48 is called twice so there are two signal/slot connections

  3. The following user says thank you to ChristianEhrlicher for this useful post:

    davidlamhauge (28th October 2018)

  4. #3
    Join Date
    Sep 2010
    Location
    Denmark
    Posts
    28
    Thanks
    10
    Thanked 3 Times in 1 Post
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QFileDialog called twice?

    Quote Originally Posted by ChristianEhrlicher View Post
    Maybe xsheet.cpp:48 is called twice so there are two signal/slot connections
    That was it!
    The connect is in the initUI() function. It's the first time I use a class with such a function, so I called initUI() rigth after ui->setupUi(this), without knowing that it is called automatically.
    You get wiser by the day...

Similar Threads

  1. QDragEnterEvent not being called
    By Nomad_Tech in forum Qt Programming
    Replies: 2
    Last Post: 12th September 2014, 01:19
  2. Replies: 7
    Last Post: 5th March 2014, 17:36
  3. Destructor not called
    By satoshi in forum General Programming
    Replies: 2
    Last Post: 23rd April 2010, 13:55
  4. Why Qt is called Qt?
    By nifei in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2009, 07:40
  5. SLOT not being called
    By steg90 in forum Qt Programming
    Replies: 4
    Last Post: 6th December 2007, 11:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.