Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to emit signal when the label text change?
QtWS25 Last Chance

How to emit signal when the label text change?

Scheduled Pinned Locked Moved Unsolved General and Desktop
ontextchangelabel
6 Posts 3 Posters 10.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MhM93
    wrote on 30 Jun 2016, 04:50 last edited by MhM93
    #1

    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?

    H.Ghassami

    J 1 Reply Last reply 30 Jun 2016, 07:01
    0
    • D Offline
      D Offline
      dheerendra
      Qt Champions 2022
      wrote on 30 Jun 2016, 05:36 last edited by
      #2

      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.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      4
      • M Offline
        M Offline
        MhM93
        wrote on 30 Jun 2016, 05:56 last edited by
        #3

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

        H.Ghassami

        1 Reply Last reply
        0
        • M MhM93
          30 Jun 2016, 04:50

          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?

          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 30 Jun 2016, 07:01 last edited by
          #4

          @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).

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3
          • M Offline
            M Offline
            MhM93
            wrote on 30 Jun 2016, 07:10 last edited by MhM93
            #5

            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>				
            
            

            H.Ghassami

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MhM93
              wrote on 30 Jun 2016, 08:38 last edited by
              #6

              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.

              H.Ghassami

              1 Reply Last reply
              1

              1/6

              30 Jun 2016, 04:50

              • Login

              • Login or register to search.
              1 out of 6
              • First post
                1/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved