Qt World Summit: Submit your Presentation

How to make QInputDialog box modal less?

  • i am using multiple QInput Dialog boxes in my UI, using the syntax like

    QString s = QInputDialog::getText(this,"Sleep Command ","Enter the number of seconds" );

    but when ever these Input dialog boxes pops up, the mainwindow becomes unresponsive, so how do i make all the QInputDialog boxes "modal less " and the mainwindow always stays responsive ??

  • Lifetime Qt Champion

    When you call QInputDialog::
    you are calling a static function that shows the dialog for you.

    If you want to use them non modal, then you must create and show the dialog your self and handle reading the data.


    Hmm that was quite old link :)

    In a newer world, lambdas make this more compact.

    QInputDialog *d = new QInputDialog;
        connect( d, &QDialog::accepted, this, [d]() {
            auto text = d->textValue();  // get text        
            d->deleteLater();// clean up
    note: we are only handling accepted so if cancel or esc is used then we leak!
    You might be able to use d->setAttribute(Qt::WA_DeleteOnClose);
    Or simply keep one instance around for full life time of app and simply hide or show as needed.

    But you change your app's logic a bit as you won't get the text now in place as it no longer blocks the main thread and
    will continue to execute while showing the dialog.
    So the text from dialog will come at later point in time than your current code.
    Just so you are aware of it.

Log in to reply