Important: Please read the Qt Code of Conduct -

[SOLVED] Issues with SIGNALS and SLOTS

  • Hi All,

    I am trying something with SIGNALS and SLOTS:

    Two classes defined:

    1. WeightTracker

    2. Display

    Header files given below


    #include <QObject>
    #include <QDate>

    class weightTracket : public QObject
    explicit weightTracket(QObject *parent = 0);
    void update (QDate d, float w);

    QDate getDate();
    float getFloat();


    void  changed();

    public slots:


    QDate date;
    float weight;



    class display : public QObject
    explicit display(QObject *parent = 0);


    public slots:

    void show(weightTracket * t);



    The "show" method in display class
    void display::show(weightTracket * t){

    qDebug() << t->getDate().toString() << t->getFloat();




    int main(int argc, char *argv[])
    QCoreApplication a(argc, argv);

    weightTracket * tracker = new weightTracket();
    QDate d1(2014,04,14);
    display * output = new display();
    return a.exec&#40;&#41;;



    When I try to run the program I get the message:

    QObject::connect: No such slot display::show(tracker)

    is the output.

    Where am I going wrong?

  • I think its is incompatibility of parameters at the connection. Normally, you have to emit at SIGNAL function the same parameters that you are going to use in SLOT function.

    Since the SIGNAL function changed() has no parameters then the SLOT function shouldn't have parameters.

  • Dont think that is the answer. Signals seldom have parameters. I think.

    Anyway how do I link the classes?

  • I updated the show() method for testing as below:

    void display::show(){

    //qDebug() << t->getDate().toString() << t->getFloat();
    qDebug() << "In the slot";



    I changed the connection to :



    The message is gone but I am not getting the qDebug() message from the display() slot.

  • Lifetime Qt Champion


    It's normal, show() is a non virtual public method from QWidget, so yours will not be called.

    Many signals throughout the Qt library have parameters.

    See the "Signal and Slot": chapter, it's explained nicely with examples

  • I have changed the name to show3(). But still does not work.

    Thanks SGaist for the link. Really helpful.

    My connection is still not working.

  • Lifetime Qt Champion

    Do you emit changed anywhere in your code ? If so and it happens before the connect statement then it won't have any effect.

  • On the dot. The connection was after the signal was emitted. Changed it now it works.

    Thanks. As usual you are a savior.

    In one class I have a QDate and float that is updated. In the second class (display class) I need to display it to the console.

    What is the best way to pass that information using SIGNALS and SLOTs?

  • Got it done.

    I am making the signal emit the QDate and float and the slot is consuming the QDate and float.

    Thank you once again.

Log in to reply