General Design: Input from keyboard into buttons



  • 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?


  • Moderators

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.