Not sure if this has a straightforward solution, but I want to write a function that shows a dialog (defined elsewhere in a class that inherits QDialog
) and returns the user input when the user has finished interacting with the dialog. In other words, something similar to the QFileDialog::getOpenFileName
static method, where a single line can open the dialog and return the user's input, instead of employing the cumbersome (in this case) signal/slot mechanism.
Intended use:
/* Shows the dialog, waits until user presses OK or Cancel,
then returns the user's choice.
*/
result = createDialogAndReturnUserChoice()
I am currently working in PyQt but I'm fine with answers in the traditional Qt4 C++ framework.
EDIT//
Here's how to do it:
dialog = CustomDialog() # creates the custom dialog we have defined in a class inheriting QDialog
if dialog.exec_(): # on exec_(), the whole program freezes until the user is done with the dialog; it returns the response of the user
# success
else:
# failure