Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Help on C++ GUI programming
Forum Update on Monday, May 27th 2025

Help on C++ GUI programming

Scheduled Pinned Locked Moved QML and Qt Quick
6 Posts 3 Posters 2.4k 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.
  • N Offline
    N Offline
    Nirmala
    wrote on 6 Aug 2012, 10:13 last edited by
    #1

    Hi All,

    Am new to this QT Creator. Trying to write the programs. Where can i get Basic Example programs.. Am stuck in Pushbutton program i don't know how to proceed..
    Kindly help on this...

    Program is when you press the button then it should display(LED ON)
    if you press the button again then it should display(LED OFF)

    Program is here:
    @
    void MainWindow::PushButtonHandler1()
    {
    ui->label1->setText("LED1 ON");
    }
    @
    when i click the button LED1 ON text is displayed.
    If i click the button second time i want the output LED1 OFF to be displayed.
    How to use if condition, what all parameters i should set ??

    [edit, code tags added, koahnig]

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AcerExtensa
      wrote on 6 Aug 2012, 10:15 last edited by
      #2

      simply check the text of the button:
      @
      void MainWindow::PushButtonHandler1()
      {
      if(ui->label1->text() == “LED1 ON”)
      {
      ui->label1->setText(“LED1 OFF”);
      return;
      }
      ui->label1->setText(“LED1 ON”);
      }
      @

      God is Real unless explicitly declared as Integer.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        Nirmala
        wrote on 6 Aug 2012, 10:44 last edited by
        #3

        Hi AcerExtensa,

        Thank you so much for the code its working as requied..

        Where can i get Example codes..

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on 6 Aug 2012, 10:58 last edited by
          #4

          While it works, I would recommend that you don't get into the habbit of using GUI elements like labels to store application state. Instead, store the state elsewhere, like in a member variable. Yes, it will look a bit more complicated now, but it is a good habbit to get into. Also, it would be good to as much as makes sense give methods names that refer to what they do, instead of to what triggers them. You might want to add a second trigger later for the same action, and then you're stuck with a method name that doesn't fit anymore.

          So, I would suggest:
          @
          //in header:
          private:
          bool m_led1On;

          //in source:
          void MainWindow::toggleButton() {
          m_led1On = !m_led1On; //toggle led

          if (m_led1On) {
          ui->label1->setText("LED1 ON");
          } else {
          ui->label1->setText("LED1 OFF");
          }

          //this would do the same:
          // ui->label1->setText(m_led1On ? "LED1 ON" : "LED1 OFF");
          }
          @

          1 Reply Last reply
          0
          • N Offline
            N Offline
            Nirmala
            wrote on 6 Aug 2012, 11:28 last edited by
            #5

            Hello Andre,

            Thank you for the suggestions...i will try to adopt these methods..

            If i want to communicate with the hardware how can i Transmit and/or Receive data(Ex. establishing Bluetooth communication)

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on 6 Aug 2012, 12:13 last edited by
              #6

              [quote author="Nirmala" date="1344252487"]Hello Andre,

              Thank you for the suggestions...i will try to adopt these methods..
              [/quote]
              You're welcome.

              [quote]If i want to communicate with the hardware how can i Transmit and/or Receive data(Ex. establishing Bluetooth communication) [/quote]
              Please ask new questions in new topics. However, have a look at "Qt Mobility Connectivity":http://doc.qt.nokia.com/qtmobility/connectivity-api.html for starters.

              1 Reply Last reply
              0

              1/6

              6 Aug 2012, 10:13

              • Login

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