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. [SOLVED] Emit signal not received

[SOLVED] Emit signal not received

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 6.6k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    sharon_obl82
    wrote on last edited by
    #1

    Hi, this is my first time trying out the emit signal, i want to pass it from one form to another on a push button so here's what I did.

    secondform.h
    @
    signals:
    void sendsignal(QString text);
    @

    secondform.cpp
    @
    void secondform::on_pushButton_clicked()
    {
    QString signal= "sent";
    emit sendsignal(signal);
    qDebug()<<"Signal Generated";

    this->close();
    

    }
    @

    mainwindow.h

    @
    public slots:
    void getsignal(QString text);
    @

    mainwindow.cpp:
    @
    #include "secondform.h"

    connect(QWidget::window(),SIGNAL(sendsignal(QString)),this,SLOT(getsignal(QString)));
    

    void MainWindow::getsignal(QString string)
    {
    qDebug()<<"Signal received"<<string;
    }

    @

    I get this message at runtime:
    QObject::connect: No such signal MainWindow::sendsignal(QString) in ..
    QObject::connect: (sender name: 'MainWindow')
    QObject::connect: (receiver name: 'MainWindow')
    Signal Generated

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      QWidget::window() returns the Window of the Widget. I'm sure this will not have signal called sendSignal. First Argument for connect should be object of SendForm. Please make the appropriate correction for connect statement. Then it will work.

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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        sharon_obl82
        wrote on last edited by
        #3

        ok understand,

        I changed and added a line but still doesn't work

        mainwindow.cpp:
        @
        secondform* window = new secondform;
        connect(window,SIGNAL(sendsignal(QString)),this,SLOT(getsignal(QString)));
        @

        The value from getsignal function is not printed :(

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          How do you show secondform?

          Do you use the window object that you allocated before connect ?

          1 Reply Last reply
          0
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            Window object which created just before the connect statement should emit the signal. Can you check where the 'window' object which created now, is emitting the signal ? Class does not emit the signal. Object emit the signals.

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

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sharon_obl82
              wrote on last edited by
              #6

              i've solved the problem by turning it around, calling the connect statement from secondform, passing the signal from secondform to mainwindow.
              this works.

              secondform.cpp:
              @
              connect(this,SIGNAL(sendsignal(QString)),parentWidget(),SLOT(getsignal(QString)));
              @

              Thank you.

              1 Reply Last reply
              0

              • Login

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