0

I am working on a project about a simple main menu interface for a mobile phone. Currently I am working on C++. I want to manipulate signals from the inputs I've typed from command line input. For example when I type "1" and press enter, I want the program to take it as a signal and do the slot operation. Here is the corresponding piece of my code:

    class MainMenu : public QDialog, private Ui::MainMenu
{
        Q_OBJECT

public:
        ...
        void setContactsSelected(int);

public slots:
        ...
        void goToContacts(int);

signals:
        ...
        void contactsSelected(int);

};

void MainMenu::setContactsSelected(int a)
{
    emit contactsSelected(a);
}

MainMenu::MainMenu(QDialog *parent)
{
    ...
    QObject::connect( this, SIGNAL( contactsSelected(int) ), this, SLOT( goToContacts(int) ) );

}
cagri
  • 1

1 Answers1

0

I assume you have already produced the code to read the users input from the command line interface (CLI). Something like:

std::string str; 
std::getline( std::cin, str);

And have a function to parse the user input

int input2int (const string &input) {
  stringstream ss(input);
  int number;

  if (!(ss >> num).fail() && (ss >> ws).eof())
  { 
      return num
  }

}

Now you only have to call your function setContactsSelected(int) passing as parameter the user's input or emit the signal void contactsSelected(int) directly.

bruno
  • 2,802
  • 1
  • 23
  • 23