Important: Please read the Qt Code of Conduct -

When i click a button i need the control to go back to main.cpp. In main.cpp it can be to any functions.

  • I have a mainwindow.cpp file and a main.cpp file
    1] in mainwindow.cpp
    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
    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";;
    qInfo() <<"End UI";
    return a.exec();

  • Moderators

    Connect your slot to QCoreApplication::quit() slot.

  • 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.

  • Moderators

    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.

  • Just write a function in your main.cpp and connect to it as shown in ("New: connecting to simple function")

  • Thank you all, the issue is solved.