PDA

View Full Version : Input



Enoctaffie
10th April 2012, 14:08
Hi

Attached is my code, I want the window to close when I click on cancel on the hobbit selector window. I also want the enable the function that when I edit the combo box, the name I put will be added to the combo box options. Please assist.
[CODE]
[#include <QInputDialog>
#include <QStringList>
#include <QApplication>

int main(int argc, char** argv) {
QApplication app(argc, argv);
app.setQuitOnLastWindowClosed(false);
QStringList hobbits, yesno;
hobbits << "Frodo" << "Bilbo" << "Samwise" << "Merry" << "Pippin";
yesno << "yes" << "no";
QString outcome, more, title("Hobbit Selector");
QString query("Pick your favorite Hobbit");
do {
QString pick =
QInputDialog::getItem(0, title, query, hobbits);
outcome = QString("You picked %1, try again?").arg(pick);
more = QInputDialog::
getItem(0, "Pick a Hobbit", outcome, yesno, 1, false);
} while (more == "yes");
}]

Enoctaffie
10th April 2012, 17:00
Hi Guys

I figured out how to do the second part of the posting can someone please assist with first part.

ChrisW67
11th April 2012, 01:51
With your code as it is you need to use the ok argument to QInputDialog::getItem() and use that as a termination condition on your loop.

Really though... if your program is going to do anything meaningful with this input you will probably need to build a user interface of your own.