When i click a button i need the control to go back to main.cpp. In main.cpp it can be to any functions.
-
wrote on 6 Mar 2018, 12:26 last edited by
I have a mainwindow.cpp file and a main.cpp file
1] in mainwindow.cpp
/
headers
/
MainWindow::MainWindow() //Constructor
{
I have connect(ui->finish, SIGNAL(clicked()), ?, SLOT(?))
}
The problem is i need this slot to go to a method in main.cpp
How can i do this?For ex
main.cpp
int main(int argc, char *argv[])
{int s = GUI_Init(argc, argv);
// on_Finish_clicked
I need my slot to come here when i click a button as i mentioned a connect() in mainwindow.cpp qInfo() << "In Main after GUI Init";
return 0;
}int GUI_Init(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
qInfo() <<"Begining UI";
w.show();
qInfo() <<"End UI";
return a.exec();
} -
Connect your slot to QCoreApplication::quit() slot.
-
wrote on 7 Mar 2018, 03:33 last edited by
Will this take my control back to the main.cpp? I may have a method in main.cpp which i need to call when the finish button is clicked.
-
Calling quit() will end the event loop, thus your call in GUI_Init() will return:
return a.exec();
And that means you'll be back in main.cpp in your case. -
wrote on 7 Mar 2018, 08:26 last edited by
Just write a function in your main.cpp and connect to it as shown in http://wiki.qt.io/New_Signal_Slot_Syntax ("New: connecting to simple function")
-
wrote on 9 Mar 2018, 08:30 last edited by
Thank you all, the issue is solved.
6/6