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
-
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
MainWindowand 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
thisif you call this somewhere within eitherMainWindoworSecondWindowclasses. In the usual caseSecondWindowshould not know aboutMainWindow, so probably not insideSecondWindowclass. 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 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
MainWindowand 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
thisif you call this somewhere within eitherMainWindoworSecondWindowclasses. In the usual caseSecondWindowshould not know aboutMainWindow, so probably not insideSecondWindowclass. 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.
-
@JonB no, i am doing this to call SecondWindow
main.h
SecondWindow *_secondwindow;main.cpp
_secondwindow = new SecondWindow(); _secondwindow->show() ``` what I am trying to do is connect SecondWindow to emit function in MainWindow -
@JonB no, i am doing this to call SecondWindow
main.h
SecondWindow *_secondwindow;main.cpp
_secondwindow = new SecondWindow(); _secondwindow->show() ``` what I am trying to do is connect SecondWindow to emit function in MainWindow@Eshya Isn't this same question as in https://forum.qt.io/topic/135973/how-to-connect-emitter-from-mainwindow-to-anotherwindow ?
-
@Eshya Isn't this same question as in https://forum.qt.io/topic/135973/how-to-connect-emitter-from-mainwindow-to-anotherwindow ?