Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Passing data from main.cpp to mainwindow and back
Forum Updated to NodeBB v4.3 + New Features

Passing data from main.cpp to mainwindow and back

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 255 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.
  • S Offline
    S Offline
    Slof
    wrote on last edited by Slof
    #1

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

    }

    J.HilkJ 1 Reply Last reply
    0
    • S Slof

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

      }

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      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


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Slof
        wrote on last edited by
        #3

        Haha sorry about that... Will do that.

        1 Reply Last reply
        1

        • Login

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