It is posible to update text in a mainwindow lineedit?
-
Hi,
Yes it is. What source are you talking about ?
-
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;}
-
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.