Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

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

    General and Desktop
    2
    7
    1455
    Loading More Posts
    • 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
      norisezp last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • N
          norisezp last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • N
              norisezp last edited by

              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 Reply Quote 0
              • SGaist
                SGaist Lifetime Qt Champion last edited by

                @
                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 Reply Quote 0
                • N
                  norisezp last edited by

                  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 Reply Quote 0
                  • First post
                    Last post