Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QFileDialog not appearing on the top even after using different window flags
QtWS25 Last Chance

QFileDialog not appearing on the top even after using different window flags

Scheduled Pinned Locked Moved Solved Mobile and Embedded
8 Posts 4 Posters 2.1k Views
  • 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.
  • S Offline
    S Offline
    Sherlin N G
    wrote on last edited by
    #1

    When the user clicks the browse button I'm doing
    QFileDialog *img = new QFileDialog;
    img->show();
    The Dialog box appears but next time when the user clicks browse button the DialogBox is minimised/opening behind by mainwindow.I tried setting different window flags but they are not working.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mvuori
      wrote on last edited by
      #2

      Give it the mainwindows or your central widget as parent in the constructor.

      1 Reply Last reply
      3
      • S Offline
        S Offline
        Sherlin N G
        wrote on last edited by
        #3

        I tried doing this
        MainWindow::MainWindow(QWidget *centralWidget) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {

        ui->setupUi(this);
        

        ...........
        }

        getting error /home/tel/Ui_IMP/mainwindow.cpp:17: error: invalid use of non-static member function
        ui(new Ui::MainWindow)
        ^

        JonBJ 1 Reply Last reply
        0
        • S Sherlin N G

          I tried doing this
          MainWindow::MainWindow(QWidget *centralWidget) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
          {

          ui->setupUi(this);
          

          ...........
          }

          getting error /home/tel/Ui_IMP/mainwindow.cpp:17: error: invalid use of non-static member function
          ui(new Ui::MainWindow)
          ^

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @Sherlin-N-G
          It's the QFileDialog constructor you're needing to change, to give the dialog a parent. You're supposed to be calling e.g. new QFileDialog(mainWindow) or new QFileDialog(mainWindow->centralWidget).

          1 Reply Last reply
          2
          • S Offline
            S Offline
            Sherlin N G
            wrote on last edited by
            #5

            i tried
            QFileDialog *file = new QFileDialog(MainWindow);
            its showing "expected primary-expression before ')' token"

            also tried this

            /home/tel/Ui_IMP/mainwindow.cpp:73: error: expected primary-expression before ‘->’ token
            QFileDialog *file = new QFileDialog(MainWindow->centralWidget);
            ^

            JonBJ raven-worxR 2 Replies Last reply
            0
            • S Sherlin N G

              i tried
              QFileDialog *file = new QFileDialog(MainWindow);
              its showing "expected primary-expression before ')' token"

              also tried this

              /home/tel/Ui_IMP/mainwindow.cpp:73: error: expected primary-expression before ‘->’ token
              QFileDialog *file = new QFileDialog(MainWindow->centralWidget);
              ^

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #6

              @Sherlin-N-G
              MainWindow is a class. You need to pass an instance, the instance of your MainWindow. That's why I wrote mainWindow (a variable of yours, whatever it is), not MainWindow (the class).

              1 Reply Last reply
              1
              • S Sherlin N G

                i tried
                QFileDialog *file = new QFileDialog(MainWindow);
                its showing "expected primary-expression before ')' token"

                also tried this

                /home/tel/Ui_IMP/mainwindow.cpp:73: error: expected primary-expression before ‘->’ token
                QFileDialog *file = new QFileDialog(MainWindow->centralWidget);
                ^

                raven-worxR Offline
                raven-worxR Offline
                raven-worx
                Moderators
                wrote on last edited by raven-worx
                #7

                @Sherlin-N-G said in QFileDialog not appearing on the top even after using different window flags:

                QFileDialog *file = new QFileDialog(MainWindow->centralWidget);

                is there really a variable called MainWindow?!
                If you are executing this code from within any widget, just pass this instead.

                --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                If you have a question please use the forum so others can benefit from the solution in the future

                1 Reply Last reply
                3
                • S Offline
                  S Offline
                  Sherlin N G
                  wrote on last edited by
                  #8

                  solved thankyou

                  1 Reply Last reply
                  0

                  • Login

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