[SOLVED] Appending text to a textbox



  • 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?



  • 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;
    }@


Log in to reply
 

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