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. [Solved] Could not make File Dialog box work. Needed help!
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 2.2k Views 1 Watching
  • 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.
  • I Offline
    I Offline
    inblueswithu
    wrote on 2 Oct 2013, 09:30 last edited by
    #1

    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();
    dialog->setFileMode(QFileDialog::Directory);
    dialog->setOption(QFileDialog::ShowDirsOnly);
    dialog->exec();
    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,
    inblueswithu

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 2 Oct 2013, 10:33 last edited by
      #2

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

      (Z(:^

      1 Reply Last reply
      0
      • I Offline
        I Offline
        inblueswithu
        wrote on 2 Oct 2013, 12:57 last edited by
        #3

        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]

        1 Reply Last reply
        0
        • I Offline
          I Offline
          inblueswithu
          wrote on 2 Oct 2013, 14:00 last edited by
          #4

          @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! :)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            sierdzio
            Moderators
            wrote on 4 Oct 2013, 05:46 last edited by
            #5

            You are welcome, happy coding.

            (Z(:^

            1 Reply Last reply
            0

            1/5

            2 Oct 2013, 09:30

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved