QSpinBox will emit the QSpinBox::valueChanged() signal when the value changes. You can connect it to some slot and read the new value there.
QSpinBox will emit the QSpinBox::valueChanged() signal when the value changes. You can connect it to some slot and read the new value there.
I have connected the QSpinBox::valueChanged() Signal to a slot from my QMainMindow class.This is a part of the code:
The qApp->aboutQt() make sure that the Signal /slot connection works.Qt Code:
double dimx;//The global scope ... void MainWindow::accepter(double d){ dimx=d; qApp->aboutQt(); } //in the main function ... MainWindow *mainWin=new MainWindow; std:: ofstream myfile; myfile.open ("data.txt"); myfile<<dimx; myfile.close(); return app.exec(); }To copy to clipboard, switch view to plain text mode
What i get in my data.txt file is the initial value of dimx.![]()
Is the slot getting called?
If you do the connection correctly then there should be no problem here.
You are getting the initial value of dimx because you're printing it too soon.
You should do something like this to see the value assigned in the slot:
Qt Code:
MainWindow *mainWin=new MainWindow; [B]mainWin->show(); [/B] int execRet = app.exec(); [B]std:: ofstream myfile; myfile.open ("data.txt"); myfile<<dimx; myfile.close(); return execRet; [/B]To copy to clipboard, switch view to plain text mode
This is one way of doing it.
You were saving the variable right after showing the
window( show exits immediately), therefore it did not had the chance to get its new value.
Generally, assigning to a static var should work, but you have to know when/where/if the var was modified prior to using it.
Regards
adonis (8th June 2007)
Bookmarks