Prompting a user with an input box? [C++]

后端 未结 8 873
遥遥无期
遥遥无期 2020-12-11 15:17

My goal is to simply use a pop-up box to ask the user for an input. I\'ve searched around quite a bit and pretty much all the results say that creating a messageBox is reall

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-11 15:51

    There is nothing like that for pure C++. Basically what you're trying to do can only be achieved by using an API call to the OS or by using some GUI library like Qt (which I recommend cause it's waaaaay easier then calling native APIs and it's also multi-platform)

    Using Qt you can show an input dialog pretty much the same way you do it on java:

    bool ok;
    QString text = QInputDialog::getText(
            "MyApp 3000", "Enter your name:", QLineEdit::Normal,
            QString::null, &ok, this );
    if ( ok && !text.isEmpty() ) {
        // user entered something and pressed OK
    } else {
        // user entered nothing or pressed Cancel
    }
    

    You can download the Qt library here: qt.nokia.com/products/developer-tools/

提交回复
热议问题