0

I'm trying to get some text input for the user for further use. For this, I used a QInputDialog:

bool ok;
QString text = QInputDialog::getText(this, tr("QInputDialog::getText()"),
                                     tr("Your input:"), QLineEdit::Normal,
                                     QDir::home().dirName(), &ok);
if (ok && !text.isEmpty()) {
    textLabel->setText(text);
}

This crahses my program at the line textLabel->setText(text);. If I comment it out, it does not crash, but the text variable stays empty. What am I missing? Thank you!

lte__
  • 7,175
  • 25
  • 74
  • 131

1 Answers1

1

First, you should initialize textLabel or give it a reference to an existing QLabel.

You can initialize it like this:

textLabel= new QLabel('some text');

Also, see QLabel documentation for more information on QLabel constructors.

Lucas Araujo
  • 1,648
  • 16
  • 25