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. [SOLVED] Appending text to a textbox

[SOLVED] Appending text to a textbox

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.8k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jediengineer
    wrote on last edited by
    #1

    Hi all, struggling to find a solution - can I pick your brains? Right now I have this function:
    @void funcs_class::sys_enable(){
    QString strIng = "Enable button pressed\n";
    QQuickItem* object = myDialog->rootObject();
    QObject textback = object->findChild<QObject>("data_output");
    QObject button = object->findChild<QObject>("en_button");
    if (textback && button)
    {
    if (!switchit)
    {
    button->setProperty("text", QString("Enabled"));
    textback->textEdit->append(strIng);
    //qDebug() << "Text sent to textbox:" << strIng;
    switchit = !switchit;
    }
    else
    {
    button->setProperty("text", QString("Enable"));
    textback->textEdit->append(strIng);;
    switchit = !switchit;
    }
    }
    return;
    }@

    "data_output is the objectName: "data_output" for the text area, and "en_button" is the "objectName:en_button" for the button.

    The goal of the function is to change the button label, and put text in a textarea. But I want to add text to the textarea (or am I using the wrong widget?). So every time the button is pressed, the button label will change (already got that to work) and the textarea will add a new line below the existing text, and eventually, I'd like it to scroll the data as it adds it.

    I am able to write to the text area, and have already proven this out, but I cannot figure out how to accomplish appending the text. Qt 5.2 doesn't have the QTextEdit header, I believe it's a QtWidgets property, and that's supposed to support the textEdit() and append() functions, but my compiler says otherwise... . In fact, it only says the QObject has no member names 'TextEdit'. Any ideas?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      jediengineer
      wrote on last edited by
      #2

      Nevermind all, I just figured it out. here was the solution:

      in my class, a private declaration:

      @QString strIng;@

      and the new code:

      @
      void funcs_class::sys_enable(){ // enable left, right, or both inverters
      QString strOng = "Enable button pressed\n";
      QQuickItem* object = myDialog->rootObject();
      QObject textback = object->findChild<QObject>("data_output"); // locates the button
      QObject button = object->findChild<QObject>("en_button");
      if (textback && button)
      {
      if (!switchit)
      {
      strIng.append(strOng);
      button->setProperty("text", QString("Enabled"));
      textback->setProperty("text", strIng);
      //qDebug() << "Text sent to textbox:" << strIng;
      switchit = !switchit;
      }
      else
      {
      strIng.append(strOng);
      button->setProperty("text", QString("Enable"));
      textback->setProperty("text", strIng);
      switchit = !switchit;
      }
      }
      return;
      }@

      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