It is posible to update text in a mainwindow lineedit?



  • I am receiving Information from a source it is possible to show that information in a lineedit or example as I get it. The lined is in a mainwindow. What approach should I take? Thank you


  • Lifetime Qt Champion

    Hi,

    Yes it is. What source are you talking about ?



  • Hello,
    I am able to get the text from the text() function of the LineEdit but it does not show in the UI.


  • Lifetime Qt Champion

    Can you share your code ?



  • #include "mylistener.h"
    #include "mainwindow.h"
    #include <QDebug>

    MyListener ::MyListener()
    {

    mai= new MainWindow();
    

    }

    void MyListener::onFrame(const Controller& controller){
    const Frame frame = controller.frame();
    handC= frame.hands().count();
    int id =frame.id();
    QString sid = QString::number(id);
    qDebug() << sid <<endl;

    hndc= QString::number(handC);
    qDebug() << hndc <<endl;
    mai->updatehand(hndc);

    }

    MaininWindow::MainWindow()
    {
    handsRead = new QLineEdit();
    connect(this, SIGNAL(hChanged(QString)),
    this, SLOT(setH(QString)));
    }
    void MainWindow::setH( QString hndc){
    handsRead->setText(hndc);
    }

    void MainWindow::updatehand(QString sthc){
    emit hChanged(sthc);
    }



  • @SGaist The MyListener class get the frames from LeapMotion sensor, then every time I get a frame I send the number of hands converted to String to the MainWindow's function updatehand. Is there something wrong in my code that don't let me update the UI QLineEdit. Thank you.



  • I was able to fix it. Thank you

    #include "mylistener.h"
    #include "mainwindow.h"
    #include <QDebug>

    MyListener ::MyListener()
    {
    myhand_C=0;
    le = new QLineEdit();
    mai.setCentralWidget(le);
    mai.show();
    }

    void MyListener::onFrame(const Controller& controller){
    const Frame frame = controller.frame();
    handC= frame.hands().count();
    int id =frame.id();
    QString sid = QString::number(id);
    qDebug() << sid <<endl;
    hndc= QString::number(handC);
    qDebug() << hndc <<endl;
    myhand_C= handC;
    //emit mai->hChanged(hndc);
    //mai->updatehand(hndc);
    le->setText(hndc);
    //qDebug()<<mai->handsRead->text()<<endl;

    }


  • Lifetime Qt Champion

    If I may, your MyListener class does too much things. It should only be responsible of listening to the device and handle frames coming from it. The GUI part should not be it's job at all.


Log in to reply
 

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