Problem with QFileDialog



  • First and for most I am new to Qt so my apologies if I use this forum incorrectly or place things in the wrong place (If I do please tell me and I will do my best to correct it).

    I seam to be having an issue with QFileDialog

    I have a method inside a class (which inherits QMainWindow) which gets the name of a file to save to. My code is shown below

    @fileSave = new QFileDialog(this, Qt::Sheet);
    fileSave->setNameFilter("PDF-Files (*.pdf)");
    fileSave->setAcceptMode(QFileDialog::AcceptSave);
    connect(fileSave, SIGNAL(finished(int)), this, SLOT(saveAccepted(int)));
    fileSave->show();@

    This works until the user clicks save or cancel in which I get a EXC_BAD_ACCESS Signal.

    I am using the stock standard 4.6 install on Mac Os X (I am running Snow Leopard with all the updates).

    The problem does not occur if I remove the line: fileSave->setAcceptMode(QFileDialog::AcceptSave); but then it displays an open dialog.

    My apologies if this is something small or I am doing something very stupid.

    Thanks

    QBALL



  • have you tried the static method QFileDialog::getSaveFileName()? I use this at most when i ned to get a file or directory. It also has the native OS - Style



  • Thanks for your quick reply

    Yes I have tried that and it did have the native style (which is preferable) but it did not use the sheet look (even when I used Qt:Sheet). I need the open dialog to be associated with the window on Mac.

    I will continue to look at how to get the static methods to use the sheets though.

    Cheers

    QBall



  • Select file/directory path using QFileDialog in Qt

    I want to show a dialog to user to select a file/directory in qt. I tried using QFileDialog to get it, but either i can set file mode or directory mode, could not able to set both. if I set QFileDialog::Directory as file mode it shows directories as well as files, but could not able to select any file. i need solution for selecting file as well as directory in the QFileDialog or help me with alternate way....



  • Select file/directory path using QFileDialog in Qt

    I want to show a dialog to user to select a file/directory in qt. I tried using QFileDialog to get it, but either i can set file mode or directory mode, could not able to set both. if I set QFileDialog::Directory as file mode it shows directories as well as files, but could not able to select any file. i need solution for selecting file as well as directory in the QFileDialog or help me with alternate way....



  • [quote author="QTanisa" date="1418189700"]Select file/directory path using QFileDialog in Qt

    I want to show a dialog to user to select a file/directory in qt. I tried using QFileDialog to get it, but either i can set file mode or directory mode, could not able to set both. if I set QFileDialog::Directory as file mode it shows directories as well as files, but could not able to select any file. i need solution for selecting file as well as directory in the QFileDialog or help me with alternate way....[/quote]

    Hi,

    You might think for setting the file mode. There are various modes that you can set in:

    enum QFileDialog::FileMode
    This enum is used to indicate what the user may select in the file dialog; i.e. what the dialog will return if the user clicks OK.
    Constant Value Description
    QFileDialog::AnyFile 0 The name of a file, whether it exists or not.
    QFileDialog::ExistingFile 1 The name of a single existing file.
    QFileDialog::Directory 2 The name of a directory. Both files and directories are displayed.
    QFileDialog::ExistingFiles 3 The names of zero or more existing files.

    "Qt documentation link":http://qt-project.org/doc/qt-4.8/qfiledialog.html#FileMode-enum

    Example:
    @
    QFileDialog dialog;
    dialog.setFileMode(QFileDialog::AnyFile);
    @



  • [quote author="QTanisa" date="1418189700"]Select file/directory path using QFileDialog in Qt

    I want to show a dialog to user to select a file/directory in qt. I tried using QFileDialog to get it, but either i can set file mode or directory mode, could not able to set both. if I set QFileDialog::Directory as file mode it shows directories as well as files, but could not able to select any file. i need solution for selecting file as well as directory in the QFileDialog or help me with alternate way....[/quote]

    Hi,

    You might think for setting the file mode. There are various modes that you can set in:

    enum QFileDialog::FileMode
    This enum is used to indicate what the user may select in the file dialog; i.e. what the dialog will return if the user clicks OK.
    Constant Value Description
    QFileDialog::AnyFile 0 The name of a file, whether it exists or not.
    QFileDialog::ExistingFile 1 The name of a single existing file.
    QFileDialog::Directory 2 The name of a directory. Both files and directories are displayed.
    QFileDialog::ExistingFiles 3 The names of zero or more existing files.

    "Qt documentation link":http://qt-project.org/doc/qt-4.8/qfiledialog.html#FileMode-enum

    Example:
    @
    QFileDialog dialog;
    dialog.setFileMode(QFileDialog::AnyFile);
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.