Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. When i click a button i need the control to go back to main.cpp. In main.cpp it can be to any functions.
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved Solved Mobile and Embedded
qtwidgetsc++ qtqt5.9
6 Posts 3 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vyshak
    wrote on 6 Mar 2018, 12:26 last edited by
    #1

    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();
    }

    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 6 Mar 2018, 12:59 last edited by
      #2

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

      (Z(:^

      1 Reply Last reply
      5
      • V Offline
        V Offline
        vyshak
        wrote on 7 Mar 2018, 03:33 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sierdzio
          Moderators
          wrote on 7 Mar 2018, 05:59 last edited by
          #4

          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.

          (Z(:^

          1 Reply Last reply
          1
          • M Offline
            M Offline
            mvuori
            wrote on 7 Mar 2018, 08:26 last edited by
            #5

            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")

            1 Reply Last reply
            1
            • V Offline
              V Offline
              vyshak
              wrote on 9 Mar 2018, 08:30 last edited by
              #6

              Thank you all, the issue is solved.

              1 Reply Last reply
              1

              6/6

              9 Mar 2018, 08:30

              • Login

              • Login or register to search.
              6 out of 6
              • First post
                6/6
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved