Important: Please read the Qt Code of Conduct -

Passing data from main.cpp to mainwindow and back

  • Hello, just started to learn a bit with QT creator.

    I have running a loop in main.cpp to check somethings, but how can I handle if a QPushButton is pushed from mainwindow and then set his text to something else?



    #include "mainwindow.h"
    #include <QApplication>
    #include <future>
    #include <stdio.h>
    #include <stdexcept>
    #include <time.h>
    #include <unistd.h>
    #include <iostream>

    void BackGround[noreturn]

    bool Toggle = false;
    while (true)
       Toggle = !Toggle;
    // Here check for button pushed from mainwindow and then adjust text


    int main(int argc, char *argv[])
    QApplication a(argc, argv);
    MainWindow w;;

    std::future<void> result_future = std::async(BackGround);
    return a.exec();


  • Moderators

    hi @Slof and welcome!

    So far your code hurts my soul 😬

    Take a moment and check out the tutorials that come with qt and QtCreator

  • Haha sorry about that... Will do that.

Log in to reply