操纵信号和qt 中命令行输入的插槽
我正在开发一个关于手机的简单主菜单界面的项目。目前我正在研究 C++。我想操纵从命令行输入输入的输入信号。例如,当我输入“1”并按回车键时,我希望程序将其作为信号并执行插槽操作。这是我的代码的相应部分:
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) ) );
}
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) ) );
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您已经生成了从命令行界面 (CLI) 读取用户输入的代码。类似于:
并且有一个函数来解析用户输入
现在您只需调用函数
setContactsSelected(int)
并作为参数传递用户的输入或发出信号void contactsSelected(int)< /code> 直接。
I assume you have already produced the code to read the users input from the command line interface (CLI). Something like:
And have a function to parse the user input
Now you only have to call your function
setContactsSelected(int)
passing as parameter the user's input or emit the signalvoid contactsSelected(int)
directly.