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时,那个并没有被获取,求解答