Trying to connect SecondWindow to MainWindow
-
hi, right now i am trying to connect secondwindow exec from mainwindow
SecondWindow::SecondWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::SecondWindow) { ui->setupUi(this); MainWindow _main; connect(this,&SecondWindow::closeTimer,_main,&MainWindow::closeTimer); }
what is the correct way to to this concept
-
@Eshya said in Trying to connect SecondWindow to MainWindow:
exec
What does this mean? Are you by any chance thinking of
QDialog::exec()
??MainWindow _main;
This cannot be right, it creates a brand new
MainWindow
. Not to mention that goes out of scope and gets destroyed at the closing}
, so it won't be around for its slot to be called.If you have some two separate instances of some
MainWindow
and someSecondWindow
, you can connect signals/slots across them once they have been created somewhere which knows about them, like:mainWindow = new MainWindow; secondWindow = new SecondWindow; connect(secondWindow, &SecondWindow::closeTimer, mainWindow, &MainWindow::closeTimer);
or appropriate
this
if you call this somewhere within eitherMainWindow
orSecondWindow
classes. In the usual caseSecondWindow
should not know aboutMainWindow
, so probably not insideSecondWindow
class. Andconnect()
s should not be done at the signalling side, only at the slot object side, or somewhere which can see both the signalling & slot objects.what is the correct way to to this concept
Don't know till I understand what "concept" you are trying to implement.
-
@Eshya Isn't this same question as in https://forum.qt.io/topic/135973/how-to-connect-emitter-from-mainwindow-to-anotherwindow ?