Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to emit signal when the label text change?



  • Hi.
    I have 3 forms (main form , password form and menu form) . The user click menu to open menu form ,but before the menu form shows,the password form display to authenticate the user.he could display RFID card or enter his Id and password. When he puts his card the socket notifier in main form recieved the RFID card data and it send to active form(my active form is password form).so the main form send card data to lblrfid :

    if(f->windowTitle()=="PassDialog")
        {
            QLabel* lbl = f->findChild<QLabel*>("lblRFID");
            //mf->processData(output);
            lbl->setText(output);
            return;
         }
    

    in password form I have a slot to authenticate the RFID card data and open menu form if the card is valid.

    void MyDialog::AcceptCard()
    {
        QString output=ui->lblRFID->text();
        bool st=database->checkPassword(NULL,output,"1");
        //this user is valid to go to menu page
        //s/he is admin
        if(st)
        {
            this->close();
            menu *m=new menu();
            m->showFullScreen();
         }
    }  
    

    I want to call AcceptCard after the label text changed.
    How can I do that?


  • Qt Champions 2017

    Label does not have any signals. If you want signals from Label, you can inherit and provide your own own signals.

    Now, based on your requirement, you can catch signal when you finished filling the first form. You may be using the line edit to fill the details on the first form. You can catch the signal from first form itself and close that form.



  • I edited my post. could you explain it with example . because I do not understand. so sorry.


  • Qt Champions 2019

    @MhM93 You can emit a signal as soon as you change the label text:

    if(f->windowTitle()=="PassDialog")
        {
            QLabel* lbl = f->findChild<QLabel*>("lblRFID");
            //mf->processData(output);
            lbl->setText(output);
            emit textChanged();
            return;
         }
    

    Connect this signal to sAcceptCard (it has to be a slot then).



  • thanks. I do like that you said. I put this code in menu button in mainform:

    MyDialog *d=new MyDialog(this);
              QObject::connect(this,SIGNAL(pressMood(QString)),
                          d,SLOT(getPressMood(QString)));
           //this connection send login result from MyDialog
           QObject::connect(d,SIGNAL(sendLoginResult(bool)),
                           this,SLOT(getLoginResult(bool)));
           QObject::connect(this,SIGNAL(recRFID(QString)),d,SLOT(AcceptCard(QString)));
           emit pressMood("menu");
           d->show();
           d->raise();
           d->activateWindow();
    

    then I emit signal when receive data from RFID module.

    void MainWindow::ReadAndProcessData()
    {
        QString output;
        QString fn;
        serialport->readcard(output);
    
        QWidget *f=QApplication::activeWindow();
        QString tmp=f->windowTitle();
        if(tmp=="User-Management")
        {
            QLabel* lbl = f->findChild<QLabel*>("lblRFIDdata");
            lbl->setText(output);
            QSound::play("ringing.wav");
            return;
        }
        if(tmp=="autotest")
        {
            QLabel* lbl = f->findChild<QLabel*>("lblRFID");
            lbl->setText(output);
             QSound::play("ringing.wav");
            return;
        }
        if(tmp=="PassDialog")
        {
           emit recRFID(output);   //   <<--- emit is here
            return;
         } 
        else
        {
             .........
         }
    }
    

    my application run but it shows the SIGSEV error in windows title :

    QString QWidget::windowTitle() const
    {
        Q_D(const QWidget);
        if (d->extra && d->extra->topextra) {         //   <<<<this line has error
            if (!d->extra->topextra->caption.isEmpty())
                return d->extra->topextra->caption;
            if (!d->extra->topextra->filePath.isEmpty())
                return constructWindowTitleFromFilePath(d->extra->topextra->filePath);
        }
    
    
    
    0	QWidget::windowTitle	qwidget.cpp	5709	0xb768dc2a	 //   <<<<this line has error
    1	MainWindow::ReadAndProcessData	mainwindow.cpp	214	0x8050253	
    2	MainWindow::qt_metacall	moc_mainwindow.cpp	99	0x80800ad	
    3	QMetaObject::metacall	qmetaobject.cpp	237	0xb73e1fa5	
    4	QMetaObject::activate	qobject.cpp	3287	0xb73eeaf6	
    5	QSocketNotifier::activated	moc_qsocketnotifier.cpp	89	0xb7436a15	
    6	QSocketNotifier::event	qsocketnotifier.cpp	317	0xb73f538f	
    7	QApplicationPrivate::notify_helper	qapplication.cpp	4302	0xb76494d4	
    8	QApplication::notify	qapplication.cpp	4110	0xb764fabb	
    9	QCoreApplication::notifyInternal	qcoreapplication.cpp	726	0xb73dc56a	
    10	sendEvent	qcoreapplication.h	215	0xb74065f7	
    11	QEventDispatcherUNIX::activateSocketNotifiers	qeventdispatcher_unix.cpp	878	0xb74065f7	
    12	QEventDispatcherUNIXPrivate::doSelect	qeventdispatcher_unix.cpp	304	0xb7406938	
    13	QEventDispatcherUNIX::processEvents	qeventdispatcher_unix.cpp	920	0xb7406d33	
    14	QEventDispatcherX11::processEvents	qeventdispatcher_x11.cpp	152	0xb76eaddd	
    15	QEventLoop::processEvents	qeventloop.cpp	149	0xb73db843	
    16	QEventLoop::exec	qeventloop.cpp	201	0xb73dbad1	
    17	QCoreApplication::exec	qcoreapplication.cpp	1003	0xb73e01fe	
    18	QApplication::exec	qapplication.cpp	3581	0xb76481c4	
    19	main	main.cpp	19	0x804ef69	
    ...	<More>				
    
    


  • I solved my problem by using this line:

     if(tmp=="PassDialog")
        {
            //QLabel* lbl = f->findChild<QLabel*>("lblRFID");
            MyDialog *tempDialog = qobject_cast<MyDialog*>(f);
           tempDialog->AcceptCard(output);
    //       emit recRFID(output);
            return;
         }
    

    and clean that connection and comment the emit code. now its worked.
    But I don't know why that code has error.


Log in to reply