Results 1 to 8 of 8

Thread: Problem with QFileDialog

  1. #1
    Join Date
    Dec 2010
    Posts
    31
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QFileDialog

    Hi, I am having a strange problem with QFileDialog. Basically i have created a very simple piece of code for test purposes:


    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QFileDialog>


    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);

    QStringList fileNames;
    QFileDialog dialog(this);
    // dialog.setDirectory("C:\\Qt\\2010.05\\test1\\");
    // dialog.setFileMode(QFileDialog::ExistingFiles);
    //dialog.setNameFilter(trUtf8("CIFs (*.cif)"));
    if (dialog.exec())
    fileNames = dialog.selectedFiles();
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    This creates the dialog box when executed but it is very slow to open and there seems to be severe problems with the operation of the dialogbox itself.

    Here is a screendump: http://img192.imageshack.us/i/picture1rz.png

    So first the 'main window'with the icons is not correct as it is not showing any of the files in the directory indicated and it doesnt update when i change the directory to be 'looked in'using the navigation controls. I also cannot double click on the icons in this window. Note that the lines that are commented out dont seem to cause the problem....

    Can someone please help me as i can create my application without being able to select and open multiple files.

    Thanks

    Matt


    Added after 11 minutes:


    UPDATE: I have just tried using the static call to QFileDialog:

    QString fileName;
    fileName = QFileDialog::getOpenFileName(this);

    And this produces and entirely different selection window (which looks more like the 'usual' windows dialog and this works correctly, however i cannot with this select and load multiple files????
    Last edited by mobucl; 20th April 2011 at 17:18.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QFileDialog

    I think taht opening a QFileDialog in QMainWindow constructor could be a problem because the MainWindow object is not yet completely constructed

    QString fileName;
    fileName = QFileDialog::getOpenFileName(this);
    And this produces and entirely different selection window (which looks more like the 'usual' windows dialog and this works correctly, however i cannot with this select and load multiple files????
    In Windows the static methods use NativeDialogs as default
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Dec 2010
    Posts
    31
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QFileDialog

    Hi mcosta,

    Thanks for the suggestion, I created a push button and a clicked slot and added the code into this:


    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <QFileDialog>

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::on_load_clicked()
    {
    QStringList fileNames;
    QFileDialog dialog(this);
    if (dialog.exec())
    fileNames = dialog.selectedFiles();
    }

    So now i get the dialog box when i click the button BUT its behaviour is exactly the same.....

    I was thinking that maybe there is a problem with QT not being able to find the standard windows dialogs unless I use static functions? Maybe i need to 'point'QT to these somewhere??

    Thanks

    Matt

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QFileDialog

    I tried your code and the result is

    opendialog.jpeg

    so it works fine!
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Dec 2010
    Posts
    31
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QFileDialog

    Well that really is strange as i it does not work on my version of QT. I will reinstall and see if that fixes the problem. Iw ill also try the code before and after building QWT which i also have installed incase this causing an issue. Will let you know of the results when i get the chance to reinstall!

    Thanks

  6. #6
    Join Date
    Dec 2010
    Posts
    31
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QFileDialog

    So coming back to this problem.....I have just reinstalled QT from scratch using the 2010.05 SDK. I have NO other plugins installed and yet i still have the same problems as described above i.e:

    QString fileName;
    fileName = QFileDialog::getOpenFileName(this,
    tr("Open Image"), "C:", tr("Image Files (*.png *.jpg *.bmp)"));


    works and gives me a standard XP dialog box but:

    QStringList fileNames;
    QFileDialog dialog(this);
    if (dialog.exec())
    fileNames = dialog.selectedFiles();

    Gives me a completetly different dialog in which the 'main window'icons are broken, files do not appear and navigation in the main window doesnt work.

    Can someone please help as this is starting to get very problematic as i really need to be able to open multiple files!

    I am thinking it could be something to do with enviromental variables??? Maybe QT doesnt know where to look to open a standard window??? HELP!

  7. #7
    Join Date
    Dec 2010
    Location
    Veszprém, Hungary
    Posts
    34
    Thanks
    2
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QFileDialog

    try to use QFileDialog::getOpenFileNames instead of QFileDialog::getOpenFileName

  8. The following user says thank you to laszlo.gosztola for this useful post:

    mobucl (2nd May 2011)

  9. #8
    Join Date
    Dec 2010
    Posts
    31
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Problem with QFileDialog

    Hi laszlo.gosztola - thanks for the message. Yes that does work around the problem of opening more than one file!

    But I really would like to get to the bottom of why i can't use the other method for opening files - anyone have the answer to this?

    Hi laszlo.gosztola - thanks for the message. Yes that does work around the problem of opening more than one file!

    But I really would like to get to the bottom of why i can't use the other method for opening files - anyone have the answer to this?


    Added after 52 minutes:


    Ok so following on I have now tried a couple of things and get some interesting results. it seems the prolem is something to do with using if (dialog.exec()) So this:

    QFileDialog dialog;
    QStringList filename;
    if (dialog.exec())
    filename = dialog.selectedFiles();

    Gives me a broken dialog (even though this is exactly the code described in the online documentation:

    http://img862.imageshack.us/i/broken.png/

    But using these lines:

    QFileDialog dialog;
    QStringList filename;
    filename = dialog.getOpenFileNames();

    Works ok and gives me this dialog box which acts as expected:

    http://img703.imageshack.us/i/workingr.png/

    BUT i cant use this code variation:

    QFileDialog dialog;
    QStringList filename;
    filename = dialog.selectedFiles();

    As this doesnt open up a selection window for me. So it appears that whilst i have a work around i cant use the code which was actually described in the QT documentation. Has anyonw any ide why this is occuring from the code i show??
    Last edited by mobucl; 2nd May 2011 at 15:45.

Similar Threads

  1. problem with qfiledialog customization (Qt4.5.2) ........
    By netfanatic in forum Qt Programming
    Replies: 0
    Last Post: 9th March 2010, 06:58
  2. problem with QFileDialog::getSaveFileName
    By navi1084 in forum Qt Programming
    Replies: 4
    Last Post: 26th June 2009, 08:38
  3. QFileDialog problem
    By jpoz in forum Newbie
    Replies: 2
    Last Post: 29th November 2008, 12:02
  4. Problem with QFileDialog::getOpenFileName()
    By spud in forum Qt Programming
    Replies: 4
    Last Post: 1st November 2007, 23:31
  5. Problem in the QFileDialog
    By joseph in forum Qt Programming
    Replies: 11
    Last Post: 7th December 2006, 10:56

Tags for this Thread

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.