⚠️ Forum Maintenance: Feb 6th, 8am - 14pm (UTC+2)
How to message the user during QFileDialog::exec() ?
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.
How/when are you sending that message ?
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 );
if (fileDialog->layout()) fileDialog->layout()->addWidget (myButton);
connect(myButton, SIGNAL(pressed()), this, SLOT(mySlot()));
The slot processing the button press looks like this:
// TRY A LABEL:
// fileDialog->setLabelText( QFileDialog::FileName, tr("Selecting All Image files.") );
// TRY A MESSAGE BOX:
// QMessageBox * msgBox = new QMessageBox(fileDialog);
// msgBox->setText(tr("My button pressed."));
Using debug printf's I see the slot being executed, but no message appears until after Accepting or Rejecting the FileDialog.
The exec call is spinning it's own event loop, you should try with open
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) );@
@const char * MainWindow::fileDialogSlot( QStringList fileNames )
and fns declared as a private const char *;
And in onDialogEnded, handle the dialog like you would after calling exec
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.