使用输入框提示用户? [C ++] [英] Prompting a user with an input box? [C++]
问题描述
我的目标是简单地使用弹出框来要求用户输入。我搜索了很多,几乎所有的结果说,创建一个messageBox是很容易:
MessageBox ,Hello World,Hello,MB_OKCANCEL);
但是,创建一个接受输入的弹出窗口更多的参与,方式做到。我可以在Google上找到的所有结果都是从2001年到2005年。我想我在这里问是否有一些更直接的解决方案近年来出现。
希望有一些好的和直接的,像在Java中:
int number = JOptionPane.showInputDialog(输入一个整数);
如果不是这样,我可以得到一个简单的解释如何做? / p>
编辑:我无法使用任何工作。 (我最后编写代码来完成Java中的工作,然后编写一行C ++代码来调用.jar文件: - /由于问题是时间敏感的,它比没有更好。
对于纯C ++,没有什么像这样的基本上你想要做的只能通过使用一个API调用OS或者通过使用一些GUI库,如Qt(我推荐因为它是waaaaay更容易,然后调用原生API,它也是多平台)
使用Qt你可以显示一个输入对话框几乎和在java上做的一样:
bool ok;
QString text = QInputDialog :: getText
MyApp 3000,输入您的姓名:,QLineEdit :: Normal,
QString :: null,& ok,this);
if(ok& .isEmpty()){
//用户输入并按下OK
} else {
//用户没有输入或按下取消
}
您可以在这里下载Qt库: qt.nokia.com/products/developer-tools/
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 really easy:
MessageBox (NULL, "Hello World" , "Hello", MB_OKCANCEL);
But that creating a pop-up that takes input is more involved and there isn't a straight forward way to do it. All of the results I could find on Google were dated somewhere from 2001 to 2005. I guess I'm here asking if some more straight forward solution has come about in recent years.
Hopefully something nice and straight forward like in Java:
int number = JOptionPane.showInputDialog ("Enter an integer");
If that isn't the case, could I get a brief explanation of how to do it?
Edit: I couldn't get anything to work. :( I ended up writing the code to do the work in Java, and then wrote one line of C++ code to call the .jar file. :-/ Since the issue was time sensitive, it was better than nothing.
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/
这篇关于使用输入框提示用户? [C ++]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!