Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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?

    Thanks

    Main.cpp:

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

    }

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

    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
    https://doc.qt.io/qt-5/qtexamplesandtutorials.html



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


Log in to reply