简体   繁体   中英

Set value from SpinBox to variable

I need to set the spinBox value to my variable, which is outside the function. So here I have variable time and wanna set it to spinBox value:

void MainWindow::on_spinBox_valueChanged(int arg1)
{
    arg1 = ui->spinBox->value();
}

I wanna store arg1 to time variable.

Shall I define time as global variable?

When the spin box value changes, the on_spinBox_valueChanged is called with the new value of the spin box. You're trying to set that input parameter to the spin box value, which does nothing and is, in fact, already the value passed in. You need to create a member variable to store the result. A global also works, although that's certainly not a good practice.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM