Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. SetText() doesn't work on a QString Variable but works on text in quotes. QT

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 4 Posters 3.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    hoomz
    wrote on last edited by
    #1

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

    @movieTitle->setText(Title);@

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

    @movieTitle->setText("Batman");@

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

    1 Reply Last reply
    0
    • A Offline
      A Offline
      aliks-os
      wrote on last edited by
      #2

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

      QString text;
      text = "super new label";
      m_label.setText(text);
      @

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

      1 Reply Last reply
      0
      • C Offline
        C Offline
        clochydd
        wrote on last edited by
        #3

        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";
        movieTitle->setText(c);
        @

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mohmo
          wrote on last edited by
          #4

          Initialize Title just before setText like this:
          Title="Hello";
          movieTitle->setText(Title);

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved