Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[SOLVED] Connecting two subclassed widgets using signal/slots
Michal last edited by Michal
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!
mcosta last edited by
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
Michal last edited by
Thank you, connecting 2 signals did the job! I spent hours to make this work...Have a nice day! ;)
mcosta last edited by SGaist