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. Variable that is updated whenever a button is presssed in Qt GUI application
Forum Updated to NodeBB v4.3 + New Features

Variable that is updated whenever a button is presssed in Qt GUI application

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 162 Views 1 Watching
  • 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.
  • O Offline
    O Offline
    okhajut
    wrote on 1 Jan 2024, 02:35 last edited by
    #1

    I have some background in C but am otherwise an electronic engineer that designs digital circuits.

    I am trying to understand how Qt programs are structured.

    Lets take an example. A Qt GUI program has a button. Everytime that button is pressed, a counter goes up. Now this counter could be declared inside the program's main or it could be declared inside the MainWindow class private area. Where should such a variable be put?

    P 1 Reply Last reply 1 Jan 2024, 04:36
    0
    • O okhajut
      1 Jan 2024, 02:35

      I have some background in C but am otherwise an electronic engineer that designs digital circuits.

      I am trying to understand how Qt programs are structured.

      Lets take an example. A Qt GUI program has a button. Everytime that button is pressed, a counter goes up. Now this counter could be declared inside the program's main or it could be declared inside the MainWindow class private area. Where should such a variable be put?

      P Offline
      P Offline
      Pl45m4
      wrote on 1 Jan 2024, 04:36 last edited by Pl45m4 1 Jan 2024, 04:36
      #2

      Hi and welcome :)

      @okhajut said in Variable that is updated whenever a button is presssed in Qt GUI application:

      could be declared inside the program's main

      You could, but makes no sense in this case.

      declared inside the MainWindow class private area

      That's what you should do.
      Depends on what you want to do further and where/for what the variable is used later.
      You might want to write some getters or add signals to it.

      Btw: If you only have some plain C knowledge, you should read about OOP and C++ basics first, before/while you start with Qt.

      • https://www.w3schools.com/cpp/cpp_oop.asp
      • https://www.w3schools.com/cpp/cpp_encapsulation.asp

      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      2

      1/2

      1 Jan 2024, 02:35

      • Login

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