PDA

View Full Version : QInputdialog doubt



iswaryasenthilkumar
19th June 2015, 10:57
bool ok;
QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
tr("Are you Sure,Do you Want to delete the Image ,Yes Or NO"), QLineEdit::Normal,
QDir::home().dirName(), &ok);
if (ok && !text.isEmpty())
{
//some action
}

actually my above code executing properly..i have doubt in output of this Qinputdialog
i getting output
QInputDialog::getText()
Are you Sure,Do you Want to delete the Image ,Yes Or NO
from the user input i getting default input(username) i need user inputtext as empty..what was mistake in above code??
please help me

d_stranz
19th June 2015, 16:11
What exactly are you trying to do here? Are you asking the user if he wants to delete something, or are you asking for the name of a directory?


to ask a simple yes / no question, use QMessageBox::question()

to get a piece of text use QInputDialog::getText() (and don't put a directory name as the default text for the edit box - QDir:: home().dirName() is doing that here)

to get a number, use QInputDialog::getInt() or QInputDialog::getDouble();

get a file or directory name, use QFileDialog::getOpenFileName() or QFileDialog::getExistingDirectory(), respectively



It would help you a lot if you read some of the Qt documentation and looked at some of the many, many examples and tutorials that come with Qt. Using this forum instead of Qt Assistant is not helping anyone.