Important: Please read the Qt Code of Conduct -

[solved] QInputDialog - change Cancel button text

  • i have here a code to display inptut dialog, what should i add to change Cancel button text?
    bool ok = false;
    QString input = QInputDialog::getText(0,Strings::uasNewUser,Strings::uasLoginName,QLineEdit::Normal,"",&ok);
    if (ok) {
    if (input != "") {
    bool insert = true;
    Sql sql;
    if (sql.connect()) {
    usernames = sql.getUsernames();
    for (int i = 0; i < usernames.length(); ++i) {
    if (usernames[i] == input) insert = false;
    if (insert) {
    } else {
    QMessageBox::warning(0,Strings::uasUserExist,Strings::uasUserWithName + " '"+input+"' "+ Strings::uasExist );
    } else {

  • Hi,
    One way I see around this is to create your QInputDialog with the constructor and call

    on it.

  • @
    QInputDialog inputDialog;
    inputDialog.setCancelButtonText("My text");@
    how will i know that OK button was clicked?
    how can i show the input dialog?

  • Lifetime Qt Champion


    Using exec and checking its return value

  • @bool ok = inputDialog.exec();@
    the exec() function will return true if OK button was clicked
    and this
    @QString returnString = inputDialog.textValue();@
    will return the text writen by user

    is it correct?

  • Lifetime Qt Champion

    exec doesn't return a boolean value, it's a QDialog::DialogCode which can be in this case mapped to a boolean value.

    For the second part, yes.

  • ok thanks i have solved my problem

  • Lifetime Qt Champion

    You're welcome !

    Since you have all running now, please update the thread title prepending [solved] so other forum users may know a solution has been found :)

Log in to reply