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. General Design: Input from keyboard into buttons
Forum Updated to NodeBB v4.3 + New Features

General Design: Input from keyboard into buttons

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 615 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.
  • A Offline
    A Offline
    ath001
    wrote on last edited by
    #1

    I'm doing an application where i have a working console program, which uses keyboard inputs. What is the best method to convert it into buttons. The issue is the code is contiguous which means its in the same code block.

    @int input;

    foo(){

    cin  >> input;
    
    if ( input == 1 ) {
        do work;
    
    if ( input == 2)  {
        do work;
    

    }
    @
    Is the proper way to divide the contiguous blocks into separate functions to be called on?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      Yes. You would create a different function (or, in C++, a class method) for each thing that needs to be done. Then they could be called as needed by whatever mechanism (button clicks, or based on if-statements like you had before, etc.)

      In Qt, you'd most likely make them SLOTs which would be connected to the pressed event on your buttons.

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0

      • Login

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