views:

67

answers:

1

hi , I just started with QT and I know the concept of signal/slot but in implementing it I have problem. take a look at my code :

#include "test.h"
#include <QCoreApplication>
test::test()
{
    // TODO Auto-generated constructor stub

}

test::~test()
{
    // TODO Auto-generated destructor stub
}



void test::fireslot(){

    qDebug("the slot fired");

}

void test::dosignaling(){
    QObject::connect(this,SIGNAL(callslot()),this,SLOT(fireslot()));

}

note : I've added the Q_OBJECT macro and inherit from QObject in test.h

and here is my test container

#include "test.h"
int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    //test t1();
    test *t2 = new test();


    t2->dosignaling();


    return a.exec();
}

code compile perfect but the nothing gonna happen . I'm not quite sure which part I've made mistake :-?

+4  A: 

The code you have in void test::dosignaling connects a slot "fireslot" to a signal "callslot", but where are you emitting the callslot signal?

You should change your code and place your QObject::connect() in the constructor (or someplace else) and change your dosignaling method to:

void test::dosignaling()
{
    emit callslot();
}

Also, you haven't shown the header file but it should include a declaration of the callslot signal, like this:

class test
{
    ...
signals:
    void callslot();
};
Idan K
And in the header, add slots: void fireslot();
Julien L.
yeah, well I figured he already did that since there's an implementation of fireslot
Idan K