Qt World Summit: Submit your Presentation

[Solved] Could not make File Dialog box work. Needed help!

  • Hi,

    I want a File Dialog box for selecting a folder in my application.
    I have used QtQuick2ApplicationViewer wizard for creating my project.
    My gui is in QML & logic in C++. I tried the following ways to get File Dialog after searching in Google.

    @int Library::fileDialog()
    QFileDialog* dialog = new QFileDialog();
    return 0;

    Second Way:

    @// Testing FileDialog
    QString path = QFileDialog::getOpenFileName(0 ,"Show Music Location", "", "", 0,QFileDialog::ShowDirsOnly);
    mediaLocation = QDir(path);
    qDebug() << path;@

    In both ways, it gave same error: QWidget: Cannot create a QWidget without QApplication

    Thought the issue is straight forward, I'm not aware how to create this. I'm inside a QGuiApplication!
    Can some one please tell me how to achieve this.

    I even tried the FileDialog component in QML. Immediately after making that visible from C++ code, it is throwing an Exception " The inferior stopped because it triggered excetption. Stopped in thread by Exception at, code: 0xc0000005; " This error is shown only in Debug mode. During runtime, it stops executing after closing the FileDialog.

    I would be great full if some one help me in this.

    EDIT : changed QApplication to QGuiApplication

    Thanks in Advance,

  • Moderators

    Are you sure you are in a QApplication or a QGuiApplication?

  • sorry, its a QGuiApplication. (As is given by the QtQuick2 Application - built in types wizard). How can I solve this?
    [quote author="sierdzio" date="1380710025"]Are you sure you are in a QApplication or a QGuiApplication?[/quote]

  • @sierdzio: It worked! <3 u man
    I changed QGuiApplication to QApplication :)
    I had to use QFileDialog::getExistingDirectory() for selecting a directory
    Thankyou. Thanks a lot! :)

  • Moderators

    You are welcome, happy coding.

Log in to reply