develoops
develoops

Reputation: 555

Signal/Slots feature for different classes in Qt C++

For just one class , i declare a slot and a signal , and in slot method definition i call signal method with emit keyword. But how can i emit signals with one class to another class which has a slot.

Well i try with a button to modify a label text. Button is created by A class (which must emit a signal) , and label is created by class B which must have a slot to modify text on it

Upvotes: 1

Views: 3946

Answers (2)

Tebe
Tebe

Reputation: 3214

It seems like you have class 1, which has a method that will be executed, and will call "emit". When that happens, the slot of another class will find out.

definition of 1st class:

class songs_text {
public:
signals:
    void send_signal();
}

int songs_text:function() { 
    emit send_signal();
}

definition of class 2:

class wind {
public slots:
    void continue_job() {
    };
}

and your main program:

Wind wind(); 
Get_source songs_text(&mtempfile);

QObject::connect(&songs_text, SIGNAL(send_signal()),
    &wind, SLOT(continue_job()));

Upvotes: 4

karlphillip
karlphillip

Reputation: 93468

Add a public method in the class named void emitSignalBlahBlah() to be a wrapper around the emit code. Then, all the other classes that need to fire this signal will access this object and call the method to do it.

Upvotes: 0

Related Questions