[SOLVED] Connecting two subclassed widgets using signal/slots
Hi! It may be a silly question but I have been struggling with this for some time...
I have a MainWindow with 2xQPushButton: button1 and button2. I click on button1 and object from ClassA (QWidget) is created and shown. In newly opened window I have another QPushButton - buttonA. I would like to click on it and emit a signal to MainWindow's button2.
The general idea is to use connect(buttonA, SIGNAL(emittedSignalFromClassA()), this, SLOT(doSomethingInMainWindow)));
The question is how to get a pointer to dynamically created obcject to be "visible" in mainwindow??
I created this example to understand how to solve my problem, my code requires similar solution. I appreciate any of Your help!
Hi and welcome to devnet,
I suggest to change your approach to the problem; the simplest way to do this is:
- Create a signal in your ClassA:
Q_SIGNALS: void buttonClicked();
- Connect the
buttonAclicked() signal to that signal
connect(buttonA, SIGNAL(clicked()), this, SIGNAL(buttonClicked()));
- In your MainWindow connect the buttonClicked signal coming from ClassA to your slot
_classA = new ClassA(); connect(_classA, SIGNAL(buttonClicked()), this, SLOT(mySlot())); _classA->show(); Happy Programming
Thank you, connecting 2 signals did the job! I spent hours to make this work...Have a nice day! ;)