Jaws
Jaws

Reputation: 497

Between windows events

I have a application with two main windows and I want to catch events from one to another. For example at button1_MouseClick event(where button 1 is situated on Form1), I want to change text to label1(where label1 is on form2). Is that possible in qt c++, and if yes, how? Could you post some code snippets, please?

P.S. I have achieved what I want using a timer and a global boolean value, but I don't like that

Thank you

Upvotes: 0

Views: 59

Answers (1)

James Elderfield
James Elderfield

Reputation: 2507

I'd have a public function within the class for form 2 which when called would change the label. Then connect the button1_MouseClick event to a private function within the form 1 class which calls the form 2 public function.

Along the lines of this perhaps:

class form1 : public QMainWindow
{
//Put in everything else class needs

private slots:
void callChangeLabel();
};

void form1::callChangeLabel()
{
//f2 is an instance of form2
f2->changeLabel();
}


class form2 : public QMainWindow
{
//Put in everything else class needs

public:
void changeLabel();
};

Upvotes: 2

Related Questions