The QLabel text not change.
-
Hi. I have a program that change the label text when that form is active. but it shows me SIGSEV error.
the mainwindow that send string to active window:UserManage *mf; QWidget *f=QApplication::activeWindow(); //if(mf!=NULL) if(f->windowTitle()=="User-Management") { //QMessageBox::warning(this, tr("Login failed"), "UserMng", QMessageBox::Ok); mf->processData(output); return; }
the second form that show the string :
//============================ void UserManage::processData(QString output) { ui->lblRFIDdata->setText(output); }
the Qlabel.cpp error:
void QLabel::setText(const QString &text) { Q_D(QLabel);-------> this line if (d->text == text) return;
error details :
0 QLabel::setText qlabel.cpp 337 0xb7aa286a -------> this line 1 UserManage::processData usermanage.cpp 53 0x806ff60 2 MainWindow::ReadAndProcessData mainwindow.cpp 162 0x804ed3f 3 MainWindow::qt_metacall moc_mainwindow.cpp 83 0x8074800 4 QMetaObject::metacall qmetaobject.cpp 237 0xb73e1fa5 5 QMetaObject::activate qobject.cpp 3287 0xb73eeaf6 6 QSocketNotifier::activated moc_qsocketnotifier.cpp 89 0xb7436a15 7 QSocketNotifier::event qsocketnotifier.cpp 317 0xb73f538f 8 QApplicationPrivate::notify_helper qapplication.cpp 4302 0xb76494d4 9 QApplication::notify qapplication.cpp 4110 0xb764fabb 10 QCoreApplication::notifyInternal qcoreapplication.cpp 726 0xb73dc56a 11 sendEvent qcoreapplication.h 215 0xb74065f7 12 QEventDispatcherUNIX::activateSocketNotifiers qeventdispatcher_unix.cpp 878 0xb74065f7 13 QEventDispatcherUNIXPrivate::doSelect qeventdispatcher_unix.cpp 304 0xb7406938 14 QEventDispatcherUNIX::processEvents qeventdispatcher_unix.cpp 920 0xb7406d33 15 QEventDispatcherX11::processEvents qeventdispatcher_x11.cpp 152 0xb76eaddd 16 QEventLoop::processEvents qeventloop.cpp 149 0xb73db843 17 QEventLoop::exec qeventloop.cpp 201 0xb73dbad1 18 QCoreApplication::exec qcoreapplication.cpp 1003 0xb73e01fe 19 QApplication::exec qapplication.cpp 3581 0xb76481c4 20 main main.cpp 15 0x804de4d ... <More>
-
Hi
I looks like you are using a non initialized pointer.UserManage *mf; // points to nothing. dangling pointer
...
mf->processData(output); // this will crash if mf never points to valid object. -
@mrjj : thanks
I change that toUserManage *mf=new UserManage; QWidget *f=QApplication::activeWindow(); //if(mf!=NULL) if(f->windowTitle()=="User-Management") { //QMessageBox::warning(this, tr("Login failed"), "UserMng", QMessageBox::Ok); mf->processData(output); return; }
I want to change the label in my form number 3 from form number 1 with . It works on tracing code with breakpoints. when receive to this method is worked
void UserManage::processData(QString output) { ui->lblRFIDdata->setText(output); }
but when finished the method it goes to QWidget.cpp class and show error here :
QString QWidget::windowTitle() const { Q_D(const QWidget); if (d->extra && d->extra->topextra) {
-
Maybe "f" is NULL ?
-
@MhM93 said:
UserManage
Is that the class where you expect the label to change?
Since you are not showing the new one you create,
you might be looking at another UserManage
than the one you make here
UserManage *mf=new UserManage; << new one
// u dont have
mf->show();
so might not see it at all ?
It wont change label for any other UserManage you might have in project.
only for "mf" -
I changed it to this code:
QWidget *f=QApplication::activeWindow(); //if(mf!=NULL) if(f->windowTitle()=="User-Management") { //QMessageBox::warning(this, tr("Login failed"), "UserMng", QMessageBox::Ok); QLabel* lbl = f->findChild<QLabel*>("lblRFIDdata"); //mf->processData(output); lbl->setText(output); return; }
and the label change. really thanks.