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. How to message the user during QFileDialog::exec() ?

How to message the user during QFileDialog::exec() ?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 1.7k 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.
  • N Offline
    N Offline
    norisezp
    wrote on last edited by
    #1

    I am writing an application in which I need to message the user from a slot called by a QFileDialog durin exec(). I have tried various ways, updating labels and QMessageBox to name 2, and have found nothing to work.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      How/when are you sending that message ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • N Offline
        N Offline
        norisezp
        wrote on last edited by
        #3

        I am trying to post the message in slot code using standard Qt API calls in C++. I'll paste a redacted copy of the code for your perusal.

        Before exec'ing the FileDialog, I add a button to its layout. The purpose of this button is to add a functionality without modifying Qt code:

        @
        myButton = new QPushButton( tr("My Button"), fileDialog );
        myButton->setDefault(false);
        myButton->setAutoDefault(false);
        if (fileDialog->layout()) fileDialog->layout()->addWidget (myButton);

        connect(myButton, SIGNAL(pressed()), this, SLOT(mySlot()));
        @

        The slot processing the button press looks like this:

        @
        void MainWindow::mySlot()
        {
        // TRY A LABEL:
        // fileDialog->setLabelText( QFileDialog::FileName, tr("Selecting All Image files.") );
        // fileDialog->update();

        // TRY A MESSAGE BOX:
        // QMessageBox * msgBox = new QMessageBox(fileDialog);
        // msgBox->setText(tr("My button pressed."));
        // msgBox->setModal(true);
        // msgBox->setWindowModality(Qt::WindowModal);
        // msgBox->raise();
        // msgBox->show();

        return;
        }
        @

        Using debug printf's I see the slot being executed, but no message appears until after Accepting or Rejecting the FileDialog.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          The exec call is spinning it's own event loop, you should try with open

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • N Offline
            N Offline
            norisezp
            wrote on last edited by
            #5

            Where may I find an example for 4.8? I finally eliminated the compile errors only to get the following:

            Object::connect: Parentheses expected, slot MainWindow::�.B
            Object::connect: (sender name: 'QFileDialog')
            Object::connect: (receiver name: 'MainWindow')

            trying to execute;

            @fileDialog->open((QObject *)this, fileDialogSlot(newFiles) );@

            with

            @const char * MainWindow::fileDialogSlot( QStringList fileNames )
            {
            return fns;
            }
            @

            and fns declared as a private const char *;

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @
              fileDialog->open(this, SLOT(onDialogEnded()));
              @

              And in onDialogEnded, handle the dialog like you would after calling exec

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • N Offline
                N Offline
                norisezp
                wrote on last edited by
                #7

                That does not sound like exactly what I want to do. Let me provide more details:

                I am trying to add a Select All button to the file dialog that does what its name suggests, selects all the files in the dialog's current directory that meet the filename filter criteria. Some directories may contain enough files that this operation takes appreciable time, during which the user might panic that the application is hung. I want to provide reassurance in the form of a message that says something like "Select all in progress," or some such. In order to do that, I need to show the message from the button press slot, while the dialog is executing. But, it seems as if the dialog is blocking the QMessageBox from displaying. So, how else should I do this? I suspect that a QProgressDialog would encounter the same blocking.

                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