SetText() doesn't work on a QString Variable but works on text in quotes. QT

  • I'm trying to change the text of a QLabel like this:


    Title is a QString. But that doesn't work. So I tested it by putting a word in quotes like:


    And that works! I can't even fathom what this issue is. Any ideas? Thanks a million!

  • @
    QLabel *m_label = new QLabel("New Label", this);
    m_label->setText("very new label");

    QString text;
    text = "super new label";

    If you have not any error messages. please trace in the debug mode the value of your variable Title

  • Hi,
    what's the symptom for not working? Any error message?
    QLabel->setText() will work with a QString variable - try setting a new variable and test:
    QString c = "Batman";

  • Initialize Title just before setText like this:

    is it working now?
    review your code and check if "Title" has a Qstring value?

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.