qq_20203153 2015-04-30 08:24 采纳率: 0%
浏览 5514

如何让lineedit动态获得用户的输入

test2::test2(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
mybutton1=new QPushButton("push this to input messages.",this);
mybutton1->setGeometry(150,200,300,100);

mybutton2=new QPushButton("exit",this);
mybutton2->setGeometry(400,300,100,100);

myedit=new QLineEdit("1",this);
myedit->setGeometry(100,100,300,100);

connect(mybutton2,SIGNAL(clicked()),this,SLOT(close()));
connect(mybutton1,SIGNAL(clicked()),this,SLOT(get_inf()));//获得lineedit输入的信号和槽函数

}

void test2::get_inf()
{
emit return_message();
}

int test2::return_message()
{
temp=0;
s=myedit->text();
temp=s.toInt();
return temp;
}
我本意是想按下获取信息的按钮(mybutton1)再获取信息,但经过试验,我发现获取信息的函数早就在程序一运行就获取了,(例如我一开始在lineedit中写入了数字1)在程序一运行那个1就被获取了,而后续我在运行出来的窗口改数字后,在按button1时,那个并没有被获取,求解答

  • 写回答

1条回答 默认 最新

  • LemonSmile_ 2015-05-02 14:44
    关注

    connect(myedit, SIGNAL(textChanged(QString), this, SLOT(onTextChanged(QString));
    test2::onTextChanged(QString text)
    {
    //获取lineedit文本
    }

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向